473,320 Members | 2,202 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,320 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 16 '05 #1
2 3983
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 16 '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 16 '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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...

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.