日期:2014-05-20  浏览次数:20788 次

NET替换字符
string str="A张三A李四A王五A马六"

现在要得到str="1,张三\n2,李四\n3,王五\n4,马六"
\n表示换行

------解决方案--------------------
C# code
string str = "A张三A李四A王五A马六";
str = string.Join("\n", str.Split('A').Select((x, i) => i.ToString() + "," + x).Skip(1).ToArray());

------解决方案--------------------
string str="A张三A李四A王五A马六";
int i=0;
str=Regex.Replace(str,"A",m=>{i++;return "\n"+i+",";});
------解决方案--------------------
C# code
        string str = "A张三A李四A王五A马六";
        int i = 0;
        string r = Regex.Replace(str, @"A([^A]+)", delegate(Match match) { i++; return i + "," + match.Groups[1].Value + "\n"; });
        Console.Write(r);