日期:2014-05-18 浏览次数:20922 次
protected void Page_Load(object sender, EventArgs e) { Response.Write(RemoveStr1("ABCDE", "ABXX") + "<BR>"); Response.Write(RemoveStr1("ABCDE", "ABCX") + "<BR>"); Response.Write(RemoveStr1("ABCDE", "XABXX") + "<BR>"); } private string RemoveStr1(string str1, string str2) { int str1Length = str1.Length; int str2Length = str2.Length; int forLength = (str1Length > str2Length) ? str2Length : str1Length; for (int i = 0; i < forLength; i++) { string str1Temp = str1.Substring(0, 1); string str2Temp = str2.Substring(0, 1); if (str1Temp == str2Temp) { str1 = str1.Substring(1, str1.Length - 1); str2 = str2.Substring(1, str2.Length - 1); } } return str2; }