具有一个字符串,例如:
string foo = "10::12"
如何拆分字符串,但仍保留结果的位置?
为澄清起见,foo
是动态的,在给定时间内字符串可能只是::12
。使用简单的拆分,我不知道所得的12
是在分隔符的左侧还是右侧。
谢谢!
答案 0 :(得分:1)
尝试这样的事情:
public static void Main()
{
ParseAndPrint("::12");
ParseAndPrint("10::12");
}
private static void ParseAndPrint(string input)
{
string[] parts = input.Split(new[] {"::"}, StringSplitOptions.None);
var left = parts[0];
var right = parts[1];
Console.WriteLine("L:" + left + " R:" + right);
}
答案 1 :(得分:1)