天天看点

c#替换字符串第一次匹配的项

string s="sdfjls广东sdfx564565498广东xcv898广东";

string fs="广东";

string th="东莞";

//先找出位置

int pos=s.indexOf(fs);

//取位置前部分+替换字符串+位置(加上查找字符长度)后部分

string newstr = s.substring(0,pos)+th+s.substring(pos+fs.length);

继续阅读