?
Solved

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

Posted on 2008-09-29
5
Medium Priority
?
309 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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