Hi all,
I am using visual studio 2005 to edit a form.cs where i am in a situation where the text entered in a particular text box must be trimmed. for eg : if the text entered in the text box in SMS_dr_6500 ,
i want to trim the text 6500 alone and save it in integer datatype. . .
please help me on this

Thanks
Sidhu

Recommended Answers

All 3 Replies

Just use regex for this problem:

string input = "SMS_dr_6500";
string output = string.Empty;
output = System.Text.RegularExpressions.Regex.Replace(input,"\\D",string.Empty);
int intValue = 0;
int.TryParse( output , out intValue );

If you don't prefer to use Regular Expressions then this will also work:

It doesn't use regex.

string abc = "SMS_dr_6500";

 int num = int.Parse(abc.Substring(abc.LastIndexOf('_') + 1));

Thanks a lot guys :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.