就是在一个字符串中有量的这样的字符串:
05/30/01418 523
03/26/01400 350
03/26/01400 296
我现在想把这些字符串全部替换成:
05/30/01,418 523
03/26/01,400 350
03/26/01,400 296
不知道该怎么实现
05/30/01418 523
03/26/01400 350
03/26/01400 296
我现在想把这些字符串全部替换成:
05/30/01,418 523
03/26/01,400 350
03/26/01,400 296
不知道该怎么实现
03/26/01400 350
03/26/01400 296
";str = Regex.Replace(str,@"/(\d{2})(\d{3})","/$1,$2");
public static string Replace(string input, string pattern, string replacement);
之所以有@是因为原始字符串和Replace方法中pattern参数中分别有/和\,@"/(\d{2})(\d{3})"是将/后面紧跟5个数字而没有空格和回车的(/01418,01400,01400)分成两组,前2个数字一组,后3个数字一组,在两组中间加一个逗号,"/$1,$2")中$1代表第一组,$2代表第2组。
不知道理解的对不对?