472,143 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

How to remove commas in a string in C# ??

Hello all,

I am entangled in a difficult situation. I wish to remove commas in a string ( for example : 1,20,000 ) that is coming as an output from another system.
I will have to process the output in my C# application. I will have to save 1,20,000 as 120000 in SQL2K database.

Please let me know how to remove the commas from the string . I have tried String.Replace already but it is not working.

Please help


Thanks so much !
Santosh
May 23 '07 #1
7 50667
dip_developer
648 Expert 512MB
Hello all,

I am entangled in a difficult situation. I wish to remove commas in a string ( for example : 1,20,000 ) that is coming as an output from another system.
I will have to process the output in my C# application. I will have to save 1,20,000 as 120000 in SQL2K database.

Please let me know how to remove the commas from the string . I have tried String.Replace already but it is not working.

Please help


Thanks so much !
Santosh
please check whether 1,20,000 is a string or not????
If it is a string then Mystring.Replace(",","") must have to work....
May 23 '07 #2
Plater
7,872 Expert 4TB
Make sure you are setting the value back.

Expand|Select|Wrap|Line Numbers
  1. string mys="1,200,000";
  2. mys=mys.Replace(",","");
  3.  
May 23 '07 #3
chinu
36
Make sure you are setting the value back.

Expand|Select|Wrap|Line Numbers
  1. string mys="1,200,000";
  2. mys=mys.Replace(",","");
  3.  
if you are sure that some currency value is coming then use
int x = Int32.Parse(st, System.Globalization.NumberStyles.Currency);
\\\rly other optons are there for the NumberStyles. Check it out.
Jun 11 '07 #4
I'm working on my first real assignment in c# where I have a csv file and i'm using StreamReader to read each line of data, and I'm pulling out two fields to compare to fields from a SQL table. My problem is it is a comma seperated file and I also have some embedded commas in quoted ("") text fields that is also seperating out each field which is causing a problem for me. I've read thru many blogs, and there has got to be some easy work around for this.

SAMPLE CSV RECORDS:
6,11,1,2,4/30/2010,6152,"FREEMAN,EDWARD J,,JR",232033,61591,P1135,ADMINISTRATIVE CLERK III,EBA,ANCHORAGE,2010,2010,6311002, , ,71172,E100,58.75,1193.52
6,11,1,3,4/30/2010,6168,"MCDONALD,PATRICIA A",311065,61948,P1135,ADMINISTRATIVE CLERK III,EBA,ANCHORAGE,2010,2010,6311003, , ,71172,E100,73.5,1143.04
Sep 23 '09 #5
Plater
7,872 Expert 4TB
Best work around for reading in a CSV i've found? Use the msJET db driver. Open the csv like you would a database (see connectionstrings.com) and read it in that way.
Sep 24 '09 #6
I found similar suggestions in other posts, but i was still hoping there was a setting i can add to streamreader to take care of that...but the oledbjet seems to be the best option.

Thank you.
Sep 24 '09 #7
string Temp=1,200,000;
Temporary=Temp.Trimend(',');
Jul 9 '14 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by soni29 | last post: by
36 posts views Thread by laredotornado | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.