I have the string in format of Rs.2, 50,000. Now I want to read the string value as 250000 and insert into database (let assume that Rs 2,50,000 coming from 开发者_开发百科third party like web services, wcf services, or from other application ).Is There any direct solution for this without using
String.Replace()
can u write the code to remove the commas.
Something like this works for me
string numb="2,50,000";
int.TryParse(numb, NumberStyles.AllowThousands, CultureInfo.InvariantCulture.NumberFormat,out actualValue);
Something like this: (I haven't tested this at all)
string str = "RS.2,50,000";
str = str.substring(3, str.length);
string arr[] = str.split(",");
string newstr;
foreach (string s in arr)
{
newstr += s;
}
Try
string str = "25,000,000";
str = string.Join(string.Empty, str.Split(','));
int i = Convert.ToInt32(str);
Try this:
string rs = "Rs.2, 50,000";
string dst="";
foreach (char c in rs)
if (char.IsDigit(c)) dst += c;
rs is source string, wihle in dst you have string you need.
Something a little different:
string rs = "Rs.2, 50,000";
string s = String.Join("", Regex.Split(rs, @"[^\d]+"));
精彩评论