str=System.Text.RegularExpressions.Regex.Replace(str,@"岩唯型(\w{4})","$1-"粗猜).Trim('山卖-')
Private Sub Form_Load()xstr = ""咐陵 '新拆档字符串
ystr = "0000000000" '原字符串
For n = 1 To Len(ystr)
If n Mod 4 = 0 Then
xstr = xstr + Mid(ystr, Len(ystr) - n + 1, 1) + "旅简乱,"
Else
xstr = xstr + Mid(ystr, Len(ystr) - n + 1, 1)
End If
Next
xstr = StrReverse(xstr)
End Sub
思路:输入一串字裂亩符,for循环字符串肆侍森的长度,每循环一次截取一个,当截取到4个了就加“,”,当字符串刚刚能够被4整除就不加“,”,实谈数现代码如下:Console.WriteLine("请输入一串字符:")
string str = Console.ReadLine()
Console.WriteLine("按4个分:")
string new_str = ""
for (int i = 0i <str.Lengthi++)
{
new_str += str.Substring(i, 1)
if ((i + 1) % 4 == 0&&(i+1)!=str.Length)
{
new_str += ","
}
}
Console.WriteLine(new_str)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)