2009/04/02

c# Replace字串

public static string Replease(string originalStr, string repleasStr, string newStr)
{
int pos = originalStr.IndexOf(repleasStr);
int len = repleasStr.Length;
if (pos != -1)
{
string strLeft = originalStr.Substring(0, pos);
string strRight = originalStr.Substring(pos + len);
return strLeft + newStr + strRight;

}
else
return originalStr;

}

沒有留言: