该字符串显示值为:
123456789012
Run Code Online (Sandbox Code Playgroud)
我需要它像:
1234 5678 9012
Run Code Online (Sandbox Code Playgroud)
此字符串中每4个字符之间应该有空格.我怎么做?
displaynum_lbl.Text = Regex.Replace(printClass.mynumber.ToString(), ".{4}", "$0");
Run Code Online (Sandbox Code Playgroud)
假设从右到左工作很好,这应该可以解决问题:
displaynum_lbl.Text = System.Text.RegularExpressions.Regex.Replace(printClass.mynumber.ToString(), ".{4}", "$0 ");
Run Code Online (Sandbox Code Playgroud)
您可以在其他 StackOverflow 答案中找到更多信息,例如:每隔 N 个字符添加分隔符到字符串?
String abc = "123456789012";
for (int i = 4; i <= abc.Length; i += 4)
{
abc = abc.Insert(i, " ");
i++;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14109 次 |
| 最近记录: |