删除文本框中的最后一个字符 [英] Removing last character in textbox

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

问题描述

这是我的代码段.

This is my code snippet.

for(int i=0; i<=textbox.text.length;i++)
{ 
textbox.text.tostring[i].tostring; 
int index=textbox.text.tostring.lastindexof(",");
if(i.equals(index)) 
 { 
  textbox.text=textbox.text.remove(index, 1);
  } 
}



我在文本框中碰巧有许多电子邮件地址,格式为me @ yahoo.com,you @ yahoo.com,但我只需要删除最后一个字符(,).问题在于它会删除两个字符.



I happen to have a number of email addresses in a textbox in this format me@yahoo.com, you@yahoo.com, but i need to delete the last character(,) only. The problem is it deletes both characters.

推荐答案

我建​​议您尝试使用此

I would suggest you try this

textbox.Text.Remove(textbox.Text.LastIndexOf('',''),1);



它更简单的方法,您可以在任何需要使用它的事件中使用它

希望我能帮忙
:-)



its easier way and you can use it in whatever the event you would like to use it in

I hope I helped
:-)


问题在您的循环条件之内,应该没有必要.

用以下代码替换您的for循环代码:


The problem is within your loop condition, there should be no need for that.

Replace your for loop code with this one :


textbox.Text = textbox.Text.Remove(Textbox.Text.LastIndexOf('',''), 1);


这应该有效:

This should work :

String orgText = textbox.text;
int i = orgText.LastIndexOf(",");
if(i != -1)
{
textbox.text = orgtext.Remove(i);
}


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

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