How to find a substring in a String.

Discussion in 'C++' started by techme, Mar 26, 2010.

  1. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    Is there a routine to find a substring in a String?
    I would like to have a routine that can be used in this way:

    String* S;
    String* SubStr = ".";
    do
    { S = Console::ReadLine() }
    while(Pos(SubStr, S) == 0);
    //Pos returns the index of the first letter of the substring inside the string. And if it doesn't find the substring, then it returns 0.
     
  2. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    I was looking for a routine that works with .net and not the old C++.

    I found what I was looking for though:

    String* S;
    String* SubStr = ".";
    do
    { S = Console::ReadLine() }
    while(S->IndexOf(SubStr) < 0);
     
  3. davidk

    davidk New Member

    Joined:
    Mar 25, 2010
    Messages:
    16
    Likes Received:
    1
    Trophy Points:
    0
    Home Page:
    http://www.firmdev.com/firm_framework
    Do you really sure what this line of code does?
    Code:
    String* SubStr = ".";
    
    It seems you are assigning the random address to your pointer-to-string variable...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice