Click to See Complete Forum and Search --> : way for string checking?


hikki
April 2nd, 2003, 10:37 PM
Is there any good way for string checking?

I want to check any exitances of some specific strings in the textbox, but I just know this method.

if (textbox1.Text.IndexOf("specific string ") > 0 )
MessageBox.Show("repeated! ", "Error Input",MessageBoxButtons.OK , MessageBoxIcon.Warning);

any best solution for that? I think mine is not a good way....

WillemM
April 2nd, 2003, 11:43 PM
well, your way sometimes doesn't work in case the string is positioned at the beginnen of the textbox.text

this is the right way:


if(textBox1.text.IndexOf(checktext) != -1)
{
//String found !
MessageBox.Show(checktext + " was found!","Text found",MessageBoxButtons.OK,MessageBoxIcon.Information);
}


I don't know any other way to find a specific string in a string.

pareshgh
April 3rd, 2003, 10:39 AM
depends upon what type of checking you are doing. if you are finding specific string then the usual way using IndexOf is Okay.

Suppose that you want to search some patterns
for example
your string is

"Blah Blah Blah 123 Blah @#$123"

now you want the digit occourences ,
you can do it by IndexOf by eXtra code is added.

using Regular Expressions you can search the patterns.

for more information you can check out MSDN for Regular Expressions.

Paresh