Solved

How do you pluck a character from a string value in C#?

Posted on 2008-09-29
5
281 Views
Last Modified: 2011-09-20
I am trying to manipulate a string value called Zip.  I want to be able to pull any digit of the zip and perform a caculation on it.  For example.  If the Zip had a value of 55522 and I wanted to add 8 to the third digit what what be the command to pull this digit out of the string.  I know it can be done with the string command in vb but I do not know the syntax in c#.

Any help is greatly appreciated.
0
Comment
Question by:kwh3856
  • 4
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22600818
you could just use regular expression to substitute or substring...I will give examples...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22600853
but since string class is immutable, the best way to do this would be to use the stringbuilder class...
0
 
LVL 21

Accepted Solution

by:
silemone earned 500 total points
ID: 22600863
StringBuilder s = new StringBuilder("astringoftext");
s[11] = 'q';
string sNew = s.ToString();

sNew is now "astringofteqt"


an example i found online...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22600883
just in case,

The StringBuilder library is at System.Text.StringBuilder...
0
 

Author Closing Comment

by:kwh3856
ID: 31501378
Thank you very much!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
Reference issues in Visual Studio 3 30
Jquery/JSON passing value from one function to another 12 38
Cant save 3D 4 20
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question