我有一个看起来像这样的传入字符串:xxxx :: xxxxx :: xxxxxx
如何在每个'::'之后拆分字符串?我只能用一个冒号来做,但不能用两个冒号.
可以说我有这个字符串:
string text = "Hi my name is <crazy> Bob";
Run Code Online (Sandbox Code Playgroud)
我想带走括号内的所有内容,结果如下:
"Hi my name is Bob".
Run Code Online (Sandbox Code Playgroud)
因此,我已经尝试过这个,我知道我一直认为while循环错了,但我无法理解.
public static string Remove(string text)
{
char[] result = new char[text.Length];
for (int i = 0; i < text.Length; i++ )
{
if (text[i] == '<')
{
while (text[i] != '>')
{
result[i] += text[i];
}
}
else
{
result[i] += text[i];
}
}
return result.ToString();
}
Run Code Online (Sandbox Code Playgroud)