1 回答
TA贡献1848条经验 获得超2个赞
static string ReplaceString(string oldstr, string filterstring,string newstring)
{
string result = string.Empty;
if (string.IsNullOrEmpty(oldstr) || string.IsNullOrEmpty(filterstring) ||newstring==null)
{
return result;
}
int position = oldstr.IndexOf(filterstring);
if (position <= 0) { return result; }
//first position
string beginstr = oldstr.Substring(0, position + filterstring.Length);
string endstr=oldstr.Substring(position+filterstring.Length);
beginstr = beginstr.Replace(filterstring, newstring);
result = beginstr + endstr;
return result;
}
string test="abccdefgccd";
Console.WriteLine(ReplaceString(test, "cc", "mmm"));
结果:
abmmmdefgccd
- 1 回答
- 0 关注
- 395 浏览
添加回答
举报