C#中的Replace函式返回的是替換後的新的字串,所以還需要在賦值一次。
String s="abcd";
s= s.Replace("a","e");
這樣就可以了,先搞清楚daoreplace的用法,明白引數的順序
using System;
publicclass ReplaceTest {
publicstaticvoid Main() {
string errString = "This docment uses 3 other docments to docment the docmentation";
Console.WriteLine("The original string is:{0}"{1}"{0}", Environment.NewLine, errString);
// Correct the spelling of "document".
string correctString = errString.Replace("docment", "document");
Console.WriteLine("After correcting the string, the result is:{0}"{1}"",
Environment.NewLine, correctString);
}
//
// This code example produces the following output:
// The original string is:
// "This docment uses 3 other docments to docment the docmentation"
// After correcting the string, the result is:
// "This document uses 3 other documents to document the documentation"
C#中的Replace函式返回的是替換後的新的字串,所以還需要在賦值一次。
String s="abcd";
s= s.Replace("a","e");
這樣就可以了,先搞清楚daoreplace的用法,明白引數的順序
using System;
publicclass ReplaceTest {
publicstaticvoid Main() {
string errString = "This docment uses 3 other docments to docment the docmentation";
Console.WriteLine("The original string is:{0}"{1}"{0}", Environment.NewLine, errString);
// Correct the spelling of "document".
string correctString = errString.Replace("docment", "document");
Console.WriteLine("After correcting the string, the result is:{0}"{1}"",
Environment.NewLine, correctString);
}
}
//
// This code example produces the following output:
//
// The original string is:
// "This docment uses 3 other docments to docment the docmentation"
//
// After correcting the string, the result is:
// "This document uses 3 other documents to document the documentation"