字符串替换在C# [英] string replace in c#

查看:176
本文介绍了字符串替换在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
字符串替换不工作

我有一个像stirng:

I have a stirng like:

string url = "abc=$abc";
url.Replace("$abc", "123");



那是什么,我估计它的URL =ABC = 123。但实际上,上面的代码乳宁后,结果仍然是ABC = $ ABC,而不是ABC = 123。

Then what I expected it url = "abc=123". But actually, after runing above code, the result is still is "abc=$abc", not "abc=123".

如何解决这个问题?

推荐答案

您想

url = url.Replace("$abc", "123");



替换()返回的新实例字符串进行替换操作。它(和所有其他字符串操作),不改变原来的字符串实例。

Replace() returns a new instance of string with the replacement operation done. It (and all other string operations) does not change the original string instance.

这篇关于字符串替换在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆