A,AB,CD,BC,ABD,ABC,
我想替换第3个逗号和第4个逗号之间的字符;每个逗号之间的字符不固定;
将BC替换成ABCD
9 个解决方案
#1
先找到第三个逗号的位置,然后截取第三个逗号和第四个逗号之间的值替换,
#2
string sss="A,AB,CD,BC,ABD,ABC,";
string [] g=s.Split(',');
for (int i = 0; i < g.Length-1; i++)
{
if(i == 3)
{
sss += ABCD + ",";
}
else
{
sss += g[i].ToString() + ",";
}
}
string [] g=s.Split(',');
for (int i = 0; i < g.Length-1; i++)
{
if(i == 3)
{
sss += ABCD + ",";
}
else
{
sss += g[i].ToString() + ",";
}
}
#3
string[] sCarray =strString.Split(new char[1] { ',' });
这样可以把strString中的字符串以","为界限分离出来!
然后你再想办法替换可能会好做一些!
这样可以把strString中的字符串以","为界限分离出来!
然后你再想办法替换可能会好做一些!
#4
<script>
var str = "A,AB,CD,BC,ABD,ABC,";
alert(str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3"));
</script>
var str = "A,AB,CD,BC,ABD,ABC,";
alert(str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3"));
</script>
#5
上面是用JAVASCRIPT写的,C#版的也差不多,看那个正则就行了
#6
用正则怎么写呢
#7
写在上面了......
str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3")
str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3")
#8
个人认为 zdqluck() 的 C#比较容易接受点…………呵呵
#9
C#版:
string str = "A,AB,CD,BC,ABD,ABC,";
Console.Write(Regex.Replace(str, "(.*,.*,.*,)(BC)(,.*)", "$1ABCD$3"));
string str = "A,AB,CD,BC,ABD,ABC,";
Console.Write(Regex.Replace(str, "(.*,.*,.*,)(BC)(,.*)", "$1ABCD$3"));
#1
先找到第三个逗号的位置,然后截取第三个逗号和第四个逗号之间的值替换,
#2
string sss="A,AB,CD,BC,ABD,ABC,";
string [] g=s.Split(',');
for (int i = 0; i < g.Length-1; i++)
{
if(i == 3)
{
sss += ABCD + ",";
}
else
{
sss += g[i].ToString() + ",";
}
}
string [] g=s.Split(',');
for (int i = 0; i < g.Length-1; i++)
{
if(i == 3)
{
sss += ABCD + ",";
}
else
{
sss += g[i].ToString() + ",";
}
}
#3
string[] sCarray =strString.Split(new char[1] { ',' });
这样可以把strString中的字符串以","为界限分离出来!
然后你再想办法替换可能会好做一些!
这样可以把strString中的字符串以","为界限分离出来!
然后你再想办法替换可能会好做一些!
#4
<script>
var str = "A,AB,CD,BC,ABD,ABC,";
alert(str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3"));
</script>
var str = "A,AB,CD,BC,ABD,ABC,";
alert(str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3"));
</script>
#5
上面是用JAVASCRIPT写的,C#版的也差不多,看那个正则就行了
#6
用正则怎么写呢
#7
写在上面了......
str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3")
str.replace(/(.*,.*,.*,)(BC)(,.*)/ig, "$1ABCD$3")
#8
个人认为 zdqluck() 的 C#比较容易接受点…………呵呵
#9
C#版:
string str = "A,AB,CD,BC,ABD,ABC,";
Console.Write(Regex.Replace(str, "(.*,.*,.*,)(BC)(,.*)", "$1ABCD$3"));
string str = "A,AB,CD,BC,ABD,ABC,";
Console.Write(Regex.Replace(str, "(.*,.*,.*,)(BC)(,.*)", "$1ABCD$3"));