我有一个字符串
NULL ({ 8 9 36 37 }) John ({ 1 }) Loizou ({ 2 3 }) delves ({ 4 }) into ({ 5 })
我怎么能得到?
NULL 8,9,36,37_
Jogn 1_
Loizou 2,3_
delves 4_
into 5
我使用c#。
答案 0 :(得分:1)
string start = @"NULL ({ 8 9 36 37 }) John ({ 1 }) Loizou ({ 2 3 }) delves ({ 4 }) into ({ 5 })";
string[] parts = start.Split(')');
string[] formattedParts = new string[parts.Length - 1];
for (int i = 0; i < parts.Length - 1; i++)
{
string internalPart = parts[i].Trim();
internalPart = internalPart.Replace("(", "");
internalPart = internalPart.Replace(" ", ",");
internalPart = internalPart.Replace(",{,", " ");
internalPart = i < parts.Length - 2 ? internalPart.Replace(",}", "_") : internalPart.Replace(",}", "");
Console.WriteLine(internalPart);
}