我应该如何从头到尾 space 删除部分字符串?

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

我正在使用 C++/CLI,我尝试从头到尾删除部分字符串 space 很长时间。

我的无效代码是:

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];
}

有什么问题?

你为什么不数第一个space,然后用这个函数呢?

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

您从头到尾都说过 space 但这不是您的程序似乎在做的事情。
是:

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

你在找什么?

简单是最好的。

string ns ="Hello world!";
int temp1 = ns.IndexOf(" ") + 1;
ns = ns.Substring(temp1);
//Console.WriteLine(ns);