CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Location
    Texas
    Posts
    119

    Question String Parsing Question

    I have a base string.

    "$****12.345*** "

    I also have a search string.

    " $*"

    I am trying to find a way to return the first position of a character that is not in my search string. In this case it would be charater 6 ("1"). Now, the System.String methods don't have a way to return this value ( I thought about using IndexOf or IndexOfAny, but these return the first found characters). The best that I have come up with is putting IndexOfAny in a for loop and then trying to get it to return a -1 when the first search character isn't found. This would be the "1" at position 6. Something like this.

    int position = 0;
    for (int count = 0; count < baseStr.Length; count ++)
    {
    position = baseStr.IndexOfAny (cmpStr.ToCharArray(), startPos);
    if (position == -1)
    return position;
    startPos ++;
    }

    Is this the best way to do it? I kinda hitting a wall here. Thanks for your help.

  2. #2
    Join Date
    Feb 2005
    Location
    Texas, U.S.A
    Posts
    81

    Re: String Parsing Question

    What is the purpose of the code? If you are trying to just get the value inside the string maybe you can try this way:

    str = str.Replace('$','');
    str = str.Replace('*','');
    The above will give you all digits other than the search string. Maybe then you can use the indexof on the resulting string.

    Also have you thought about using regular expressions? I guess it all depends on what end result you expect. Hope this helps....
    (Key)Success = BalancedLifeStyle.Invoke(Moderation,null,null);

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