c#里面如何分割字符串?将一个字符串按两个两个的分组成一个字符串组 比如说“abcdef"分成“ab""cd”"ef"

2024-11-18 15:52:04
推荐回答(3个)
回答(1):

正则式,一句话,要引用using System.Text.RegularExpressions;
var str = "adkflsdllkqrr";
string[] result = Regex.Split(str, "(?<=\\G.{2})");

回答(2):

string a = "abcdefg";
string[] b = new string[a.Length];
for (int i = 0; i < a.Length / 2; i++)
{
b[i] = a.Substring(i*2,2);
Console.WriteLine(b[i]);
}

回答(3):

for循环 + substring()