字符串替换功能 [英] string replace function

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

问题描述

文本框包含5个输入

表达式是5 * x

textbox contains 5 as input

expression is 5*x

string exp = textBox1.Text.ToString();
            string expression = exp.Replace("x", exp);
            txtCalculate.Text = expression;



我得到了这个输出

5 * 5 * x



I got this output

5*5*x

推荐答案

Him

您的代码没有意义.这是你想要的吗? (textBox1.Text为"5")
Him

your code doesn''t make sense. Is this what you want? (textBox1.Text is "5")
string exp = "5*x";
string expression = exp.Replace("x", textBox1.Text);
txtCalculate.Text = expression; //5*5


这就是你应该得到的.
请参阅代码中的注释:

That''s what you should get.
See the comments in the code:

string exp = textBox1.Text.ToString(); //exp = 5*x
string expression = exp.Replace("x", exp); //expression = 5*(5*x) - I have replace x by value of exp
txtCalculate.Text = expression; //txtCalculate.Text=5*5*x



问题出在哪儿?编辑您的问题以添加更多信息.

PS-我回答了这个问题并删除了它,因为它似乎出现了两次.但是后来我意识到这是另一个答案.所以我又写了(而不是粘贴了).



Where is the problem? Edit your question to add more information.

PS - I answered the question and deleted it because it seemed to appear twice. But later I realised it was other answer. So I wrote (rather pasted) it again.


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

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