与string.replace(或其他字符串修改)不工作 [英] string.Replace (or other string modification) not working

查看:88
本文介绍了与string.replace(或其他字符串修改)不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关以下code,我不能得到与string.replace工作:

For the following code, I can't get the string.Replace to work:

someTestString.Replace(someID.ToString(), sessionID);

当我调试,并检查someID.ToString它有108716307
和会话ID有108716308

when I debug and check someID.ToString it's got "108716307" and sessionID has "108716308"

不知道为什么,这将不若someTestString工作如下:

"The:<br>Photo: <b><a href='myfoldert/108716305-1.jpg' target='_blank'>108716305-1.jpg</a> (originalphoto.gif)</b><br>Background Color: <b>223324</b>"

结果应该是这样的:

the result should be this:

"The:<br>Photo: <b><a href='myfoldert/108716305-1.jpg' target='_blank'>1087163085-1.jpg</a> (originalphoto.gif)</b><br>Background Color: <b>223324</b>"

,但它并没有改变。对于someTestString字符串打我的code后保持不变。

but it doesn't change. The string for someTestString remains unchanged after hitting my code.

推荐答案

字符串是不可改变的。与string.replace的结果是一个新的字符串与替换值。试试这个:

Strings are immutable. The result of string.Replace is a new string with the replaced value. Try this:

var newString = someTestString.Replace(someID.ToString(), sessionID);

这篇关于与string.replace(或其他字符串修改)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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