【发布时间】:2015-05-28 01:01:10
【问题描述】:
如果我有一些像这样的数字的字符串
var nr = "00011122233345721";
如何将字符串中的第八个和最后一个元素替换为*,使字符串变为0001112*23334572*
【问题讨论】:
-
只使用
[]运算符。 string 是char的数组 -
@Tigran:那行不通。
string的索引器是只读的 -
快速简单的方法是
first check the length of the string if it's >= 8 then use the substring function along with the string.Replace function -
你也可以使用正则表达式:string s = Regex.Replace(nr,@"(.{7}).(.*?).$","$1*$2*")