Search code examples
winformsc++-cli

How should I delete part of string from beginning to first space?


I'm using C++/CLI and I was trying to delete part of string from beginning to first space for a long time.

My code that doesn't work is:

String^ ns = gcnew String("Hello world!");
int temp1 = ns->IndexOf(" ");
int temp2 = ns->Length;
for (int i =temp1 +1; i < temp2; i++) {
    ns+= ns[i];
}

What is the problem?


Solution

  • Why don't you count where is the first space, then use this function?

    str = str->Remove( CoordsStart , CoordsEnd-CoordsStart );