CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Location
    Japan
    Posts
    120

    Lightbulb way for string checking?

    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....

  2. #2
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    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:

    Code:
    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.
    WM.

    What about weapons of mass construction?

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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
    - Software Architect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured