[英]How to replace ' character in textbox
I have a text box where the user must enter a text, I want to make a control on the input (ie replace the character '
and '
by another character or delete it from the text entered by the user. 我有一个文本框,用户必须在其中输入文本,我想对输入进行控制(即用另一个字符替换字符'
和'
或从用户输入的文本中删除它。
I tried with textbox.TrimEnd()
or textbox.Replace(', abc)
but I get no results 我尝试使用textbox.TrimEnd()
或textbox.Replace(', abc)
但没有结果
string.Replace() should have strings as arguments. string.Replace()应该将字符串作为参数。
This will not work: 这将不起作用:
textbox.replace(',abc)
As the character '
is not a string or even a character as far as the interpreter is concerned. 就解释器而言,字符'
不是字符串,甚至不是字符。 And of course, if abc
is a string variable you may use abc
. 当然,如果abc
是一个字符串变量,则可以使用abc
。
Try instead: 请尝试:
textbox.text.Replace("'", "abc")
Note the '.text' so you can access the text in what I'm assuming to be a textbox object with a text property. 注意“ .text”,因此您可以在我假设是带有text属性的文本框对象中访问文本。
I suggest you to use 我建议你用
textbox.Replace("'", "new value") Iwish this help you brother textbox.Replace(“'”,“新值”)希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.