473,383 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

check word length

DOes anyone know how to check the length of words in a string?

I want all the word in a string to be less than 100 char to prevent buffer
overflow.
Thanks.
Aaron


Nov 18 '05 #1
2 1155
Aaron,

You could try something like this

string msg = " This is my message";

public class StringUtil
{
public StringUtil()
{
}

public bool IsValidWordLenght(string value, int maxLenght)
{
string[] words = value.Split(' ');
foreach(string word in words)
{
if( word.Trim().Length > maxLenght)
return false;
}
return true;
}
}

Then call it like this (it will trim of leading and trailing whitespaces if
there are any).

string message ="This is a message";
bool ret = StringUtil.IsValidWordLenght(message, 100);

HTH,

//Andreas

"Aaron" <ku*****@yahoo.com> skrev i meddelandet
news:OP**************@TK2MSFTNGP12.phx.gbl...
DOes anyone know how to check the length of words in a string?

I want all the word in a string to be less than 100 char to prevent buffer
overflow.
Thanks.
Aaron

Nov 18 '05 #2
On Sun, 11 Apr 2004 14:57:09 -0700, "Aaron" <ku*****@yahoo.com> wrote:
DOes anyone know how to check the length of words in a string?

I want all the word in a string to be less than 100 char to prevent buffer
overflow.
Thanks.
Aaron


I'm just begining to learn C#, so most likely this isn't what you're
looking for but, I thought I would mention my thought :)
string s;
s="served";
int i;
i=(s.Length);
Console.WriteLine("i is: " + i );

you can use an if/then or a try/catch block if the length is 100 or
more?

-Tony!-

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric A. Johnson | last post by:
Hi, Thanks for reading this. How do I list all possible permutations of a word? I've figured out how to get all the characters in alphabetical order. I then want to display every possible...
4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
4
by: Aaron | last post by:
DOes anyone know how to check the length of words in a string? I want all the word in a string to be less than 100 char to prevent buffer overflow. Thanks. Aaron
15
by: tabonni | last post by:
I want to check each button groups and save the checked value into a 2 dimensional array. But, it doesn't work. Could anyone tell me what's wrong with my code. My code is as follow: <html>...
5
by: Krechting | last post by:
Hi ALl, I have a code that checks if the documents in a hyperlink field are still where they should be. I use fileexist(). First I want to filter out all the hyperlink fields that are empty. I...
2
by: CR | last post by:
having a problem with the final strcpy of filename from *argv into a structure containing an array with 20 elements called fname It seems that strcpy & strncpy aren't stopping after null is found...
10
by: Douglas G | last post by:
I've tried various ideas on this problem, but I don't see word wrapping. Can you point out what is wrong? It's a K&R exercise, and I'm still new to programming. Other pointers would be helpful...
4
by: s.subbarayan | last post by:
Dear all, I would like to know the easiest efficient way to set or inject a particular value in the given word or byte?The problem is: I have to implement a function which will set a value from...
1
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.