Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 14-Jul-10 21:59pm
v2

if (textBox1.Text.EndsWith(','))
   textBox1.Text = textBox1.Text.SubString(0, textBox1.Text.Length -1);
 
Share this answer
 
v2
Comments
ashu2188 15-Jul-10 6:28am    
Reason for my vote of 5
gud solution.
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!
 
Share this answer
 
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.
 
Share this answer
 
regex

\d+\,?\d+
 
Share this answer
 
using split it is possible
textbox.text.split(",")[0];
 
Share this answer
 
Comments
Johnny J. 15-Jul-10 4:00am    
Reason for my vote of 1
Not a good solution
raju melveetilpurayil 15-Jul-10 5:36am    
Reason for my vote of 1
i agree with Johnny J

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900