string mystring="the are boys";
string[] tags = {"the"};
string[] replace ={"they"}
mystring.Replace(tags[0],replace[0]) // is not working
mystring.Replace("the","they") // is working
Run Code Online (Sandbox Code Playgroud)
我认为两者都是一样的,但第一个声明不起作用.第二个是.请帮我解决问题.
Tim*_*ter 11
我假设您没有String.Replace为变量分配返回值.但由于字符串是不可变的,你必须这样做:
mystring = mystring.Replace(tags[0],replace[0])
Run Code Online (Sandbox Code Playgroud)