473,411 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 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 50927
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

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

Similar topics

3
by: soni29 | last post by:
hi, how can i remove a string from an existing string in javascript. i have a textbox in a form and want to make sure that when the user clicks a button that certain words are moved, like all...
0
by: TomislaW | last post by:
is it possible?
10
by: teenIce | last post by:
Hi all, Does anyone have suggestion what can I do to remove some string from a string? Like this : Original : I have a cat. Remove : have Result : I a cat. Thanks in advance.
11
by: Dooza | last post by:
Using ASP/VB I need to remove unwanted commas from the end of a field that will be use in an array. There are items in the field that are comma separated, so I don't want to remove them, just the...
36
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have an array of strings. What is the simplest way to remove the elements that are empty, i.e. where the expression "empty($elt)" returns true? Thanks, - Dave
7
by: cbjones | last post by:
I am trying to create a query such that when pulling data from a table, then If the result is "NULL", replace "NULL" in the column with a "blank"...OR... if the result is a string (not NULL),...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.