473,718 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

48 New Member
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 51016
dip_developer
648 Recognized Expert Contributor
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.Replac e(",","") must have to work....
May 23 '07 #2
Plater
7,872 Recognized Expert Expert
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 New Member
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.Globaliz ation.NumberSty les.Currency);
\\\rly other optons are there for the NumberStyles. Check it out.
Jun 11 '07 #4
mzmatterafact
3 New Member
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,P1 135,ADMINISTRAT IVE CLERK III,EBA,ANCHORA GE,2010,2010,63 11002, , ,71172,E100,58. 75,1193.52
6,11,1,3,4/30/2010,6168,"MCDONALD,PATRICIA A",311065,61948,P1 135,ADMINISTRAT IVE CLERK III,EBA,ANCHORA GE,2010,2010,63 11003, , ,71172,E100,73. 5,1143.04
Sep 23 '09 #5
Plater
7,872 Recognized Expert Expert
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 connectionstrin gs.com) and read it in that way.
Sep 24 '09 #6
mzmatterafact
3 New Member
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
RoopaWali
1 New Member
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
21526
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 instances of "hello" should be taken out of the text the user typed in the textbox. any ideas? thank you.
10
60484
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
10483
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 end ones, could be anywhere up to 5 unwanted commas. Any ideas? Cheers, Steve
36
9169
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
30426
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), strip all commas from the resulting string and show the result in the column (Example: showing "ABC, Inc." as "ABC Inc.")...AND... label the column with a heading. So far, I have totally failed in attempts to write this line of my query... Many...
0
8827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8723
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9354
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9120
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6652
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3182
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.