110,534
社区成员
发帖
与我相关
我的任务
分享
string test = "abcdefg";
string result = System.Text.RegularExpressions.Regex.Replace(yourStr, @"(?<!^)[a-zA-Z]{2}", ",$0", RegexOptions.RightToLeft);
string s = "abcdefg";
for (int i = s.Length - 2; i > 0; i -= 2)
s = s.Insert(i, ",");
string str = Console.ReadLine();
char[] arr = str.ToCharArray();
string newstr = string.Empty;
for (int i = 0; i < arr.Length; i++)
{
newstr += arr[i].ToString();
if ((i + 1) % 2 == 0)
{
newstr += ",";
}
}
if (newstr.Substring(newstr.Length - 1, 1) == ",")
newstr.Substring(0, newstr.Length - 1);
Console.WriteLine(str);
Console.ReadLine();
static String AddSeperators(string input)
{
if (string.IsNullOrEmpty(input)) return input;
StringBuilder sb = new StringBuilder();
sb.Append( input.Substring(0, 2 - input.Length % 2) );
for (int i = 2 - input.Length % 2; i < input.Length; i += 2)
{
sb.AppendFormat(",{0}{1}", input[i], input[i + 1]);
}
return sb.ToString();
}