如何删除文本框中的最后一个字符?

问题描述:

在我的文本框中,输入一些数字,例如123,456,789,.如果我输入的数字的最后一个字符是,",那么我需要将其删除(,"),否则我不应该删除任何内容

我怎么做?请帮我解决.

谢谢.

In my textbox I enter some numbers like 123,456,789,. If the last character of my entered number is "," then I need to remove it (",") otherwise I shouldn''t remove anything

How do I do that? Please help me with a solution.

Thanks.

if (textBox1.Text.EndsWith('',''))
   textBox1.Text = textBox1.Text.SubString(0, textBox1.Text.Length -1);


您可以尝试:
textbox.text.TrimEnd({'',''})

缺点(或优点)是,所有逗号最后都被删除,而不仅仅是一个.

否则,只需检查字符串中的最后一个字符,如果它是逗号,则将其删除.

祝你好运!
You could try:
textbox.text.TrimEnd({'',''})

A disadvantage (or advantage) is that all comma''s are removed at the end and not just one.

Otherwise just check the last character in the string and remove this if it is a comma.

Good luck!


string str = textbox1.text;
int i = str.length;
如果(str(i-1).tostring()==,")
str = str.remove(str.length-1);


尝试获取代码的逻辑插入.
string str = textbox1.text;
int i = str.length;
if (str(i-1).tostring() == ",")
str = str.remove(str.length-1);


try to get logic insted of code.