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

问题描述:

这是我的代码段.

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);
}