473,406 Members | 2,843 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,406 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 1157
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.