我有一个字符串,想知道如何将这些值拆分为单独的变量
string c = "1237^^^John^^^Abraham^^Dr";
我想将 John Abraham 博士放入一个变量中。
String name = "Dr. John Abraham";
非常感谢您对此的建议。我尝试了indexof,但无法正确找出。
最佳答案
您可以使用 String.Split
并以 ^
作为分隔符,并使用 RemoveEmptyEntries
var input = "1237^^^John^^^Abraham^^Dr";
var split = input.Split(new[]{'^'}, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine("{0}. {1} {2}", split[3], split[1], split[2]);
关于C# 在特定字符后连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51096504/