将String.Replace方法与变量一起使用 [英] Using String.Replace method with variables
问题描述
大家好,
我很难以自己想要的方式获得价值,例如;
在我的代码中,我有这样的变量;
Hello all,
I am having difficulty getting values the way I want, For example;
in my code i have variables like this;
string strName = string.Empty;
Name = txtName.Text; (Lets say the value of txtName.Text is "Robert")
string strParagraph = string.Empty;
我正在从数据库中分配"strParagraph"的值.
我从数据库中检索的值是这样的=用户名是{$ user $}."
我想做的是:将"{$ user $}"替换为我之前分配的名称"字段.
所以我在做的是
I am assigning the value of "strParagraph" from the DB.
the value that i am retrieving from the db is something like this= "The name of the user is {$user$}."
What I want to do is: replace the "{$user$}" with the Name field that I assign previously.
so what I am doing is;
strParagraph = strParagraph.Replace("{$user$}", "+ Name+");
,因此最终的字符串将如下所示:
so the final string will look like this:
strParagraph = "The name of the user is" + Name +".";
它正在执行replace方法,但是我无法获取名称"中的值.
像这样的结果应该是这样的:
用户名是Robert."
但它显示为:
用户名是+名称+."
我怎样才能解决这个问题?谢谢
It is making the replace method but I can not get the value which is inside the "Name".
Like the outcome should be like this:
"The name of the user is Robert."
but it is appearing as:
"The name of the user is + Name +."
how can i fix this? Thanks
推荐答案
user
}."
我想做的是:替换"{
}."
What I want to do is: replace the "{
user
这篇关于将String.Replace方法与变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!