Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > check word length

Reply
Thread Tools

check word length

 
 
Aaron
Guest
Posts: n/a
 
      04-11-2004
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




 
Reply With Quote
 
 
 
 
Andreas Håkansson
Guest
Posts: n/a
 
      04-11-2004
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" <(E-Mail Removed)> skrev i meddelandet
news:OPAOX$(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Tony
Guest
Posts: n/a
 
      04-12-2004
On Sun, 11 Apr 2004 14:57:09 -0700, "Aaron" <(E-Mail Removed)> 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!-

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
911...Need Help! : Length cannot be less than zero. Parameter name : length manmit.walia@gmail.com ASP .Net 2 01-10-2006 03:29 PM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM
left(string, length) or right(string, length)? Sam ASP .Net 3 02-17-2005 12:01 PM
System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length =?Utf-8?B?SG96aQ==?= ASP .Net 1 06-01-2004 11:06 PM
How to get length of string? length() problems Mitchua Perl 5 07-17-2003 12:08 AM



Advertisments