如何更改文本框中特定字符串的值C# [英] How to change the value of specific strings in a textbox C#

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

问题描述

Hello CodeProject,

我的问题对于那些知道的人来说并不难,但对于像我这样有着大量C#的简单程序员而言,这个问题太多了。

正如我的标题所说我想要创建这样的东西:

假设有一个文本框,用户在其中写了一些内容,

在整个事情中,快乐这个词是分散的。

有一个按钮,当用户只点击单词快乐变为真棒时,句子的其余部分始终相同。

任何代码?

对不起,如果我没有尝试任何东西,因为我没有想法。

Hello CodeProject,
My question isn't that hard for those who know but it's too much for a simple programmer like me with a big heap of C#.
As my title says I want to create something like this :
Let's assume that there is a textbox in which the user has written something,
Throughout the whole thing the word happy is scattered.
There is a button when which the user clicks only the word happy is changed to awesome, the rest part of the sentence is same throughout.
Any code?
Sorry if I didn't try anything, cause I was out of ideas.

推荐答案

我假设你的文本框name是TextBox1。现在双按鼠标左键。它将创建onClick函数的存根。把这个代码放在那里:



I assume that your textbox name is TextBox1. Now double press left mouse key on button. It will create a stub of onClick function. Put there this code:

this.TextBox1.Text = this.TextBox1.Text.Replace("HAPPY", "AWESOME");



编译并运行项目


Compile and run your project


尝试:

Try:
MyTextBox.Text = MyTextBox.Text.Replace("HAPPY", "AWESOME");





以后不要再大喊大叫,否则一个人不会回答你...使用所有大写字母被认为是在互联网上大喊大叫,粗鲁(使用所有小写字母被认为是幼稚的)。如果你想被认真对待,请使用适当的大写字母。



And DON'T SHOUT in future, or I for one will not be answering you... Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.


这篇关于如何更改文本框中特定字符串的值C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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