Click to See Complete Forum and Search --> : Question about manipulating strings


Green Fuze
April 13th, 2005, 06:15 AM
Hey!


I'm trying to display on a MessageBox only a part of a string.

let say that my string (strWord) looks like this:

<line1>hello</line1>
<line2>whats up?</line2>
<line3>everything is ALRIGHT???</line3>

now, I want to display only the second line (whats up?),
now, I know how to display charachters from the most right (strWord.Left(int...) or strWord.Right(int...)), and I can calculate the number of chars I need to start displaying, and to calculate how many chars I need to display, BUT, what I don't know is how to tell VC to actually start display from there.

meaning, if I want to start displaying from the 29th charachter (which is the "w" of the "whats up?") how do I do that? and how do I tell him to display only the next 9 chars?

THANKS!!!

dumbquestion
April 13th, 2005, 09:15 AM
How about this?

private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
String *strWord = S"hello\nwhat's up?\neverything is ALRIGHT???";
int start, stop, length;
start = 6;
stop = 15;
length = stop - start + 1;
MessageBox::Show(strWord->Substring(start, length));
}



Or this? the "Split" member function of the String* class is pretty handy for segmenting a String* that is delimited by some characters. If you wanted to separate by whitespaces and commas, you could use delimStr = S" ,\t" (\t is the tab character), for example.


private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
String *strWord = S"hello\nwhat's up?\neverything is ALRIGHT???";
String* delimStr = S"\n";
Char delimiter[] = delimStr->ToCharArray();
String* split[] = 0;
split = strWord->Split(delimiter);
MessageBox::Show(split[1]);
}


Hope it helps.

Green Fuze
April 13th, 2005, 07:29 PM
Hey Thanks!!! :-)