Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seaching a string 1

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have a string that is in this format:

AP:::Withhold<space><cutnumber>$$$<misc text>

I want to put everything up to and including the $$$ as one string and everything after the $$$ as the second string. How can I search for the $$$ in the string and split the text. The text will be coming in the form of a file that I will be opening and reading.

Thanks.

Mindy
 
Look at the Pos and subString methods if you are using AnsiString[/i].
Code:
String FromFile = &quot;AP:::Withhold<space><cutnumber>$$$<misc text>&quot;;
String FirstPart = &quot;&quot;;
String SecondPart = &quot;&quot;;

int TheSubStringPosIs = FromFile.Pos(&quot;$$$&quot;); // This is position of $$$

if (TheSubStringPosIs > 0)
{
    // If the position is zero, the sub string does not exist.

    int StrLength = FromFile.Length(); // String length
    FirstPart = FromFile.SubString(0,TheSubStringPosIs); // Should be everything to $$$
    SecondPart = FromFile.SubString(TheSubStringPosIs+3, StrLength); // The rest
}

This is off the top of my head so you may have to play with the code a bit.

If you are using the standard C++ string there are similar functions or you can use the STL's strstream functions.

James P. Cottingham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top