如何删除文本框中的最后一个字符? [英] How to remove last character in textbox?

查看:196
本文介绍了如何删除文本框中的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的文本框中,输入一些数字,例如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.


这篇关于如何删除文本框中的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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