我想用“;”替换“;”;在我的字符串中。C#字符串替换
例如:
更改此
“文本”, “文本”, “文本”,
此
“文本;文本; Text“,
我一直在尝试line.replace(... , ...)
,但无法正常工作。
任何帮助,将不胜感激。
我想用“;”替换“;”;在我的字符串中。C#字符串替换
例如:
更改此
“文本”, “文本”, “文本”,
此
“文本;文本; Text“,
我一直在尝试line.replace(... , ...)
,但无法正常工作。
任何帮助,将不胜感激。
你需要躲避搜索字符串内的双引号,像这样:
string orig = "\"Text\",\"Text\",\"Text\"";
string res = orig.Replace("\",\"", ";");
注意更换不会发生“到位” ,因为.NET字符串是不可变的。调用后原始字符串保持不变;只有返回的字符串res
将有替换。
如何line.Replace(@""",""", ";");
var str = "Text\",\"Text\",\"Text";
var newstr = str.Replace("\",\"",";");
确保正确逃生引号。
string line = "\"Text\",\"Text\",\"Text\",";
string result = line.Replace("\",\"", ";");
//Replace Method
Here I'm replace old value to new value
string actual = "Hello World";
string Result = actual.Replace("World", "stackoverflow");
----------------------
Output : "Hello stackoverflow"
你不能使用string.replace..as一个字符串分配你不能操纵。因为我们使用字符串builder.here是我的例子。在html页面中我添加了[Name]哪个被替换为Name.make确定[Name]是唯一的或者你可以给出任何唯一的名称
string Name = txtname.Text;
string contents = File.ReadAllText(Server.MapPath("~/Admin/invoice.html"));
StringBuilder builder = new StringBuilder(contents);
builder.Replace("[Name]", Name);
StringReader sr = new StringReader(builder.ToString());
什么不能正常工作? – SimpleVar