• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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

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
kwh3856
Asked:
kwh3856
  • 4
1 Solution
 
silemoneCommented:
you could just use regular expression to substitute or substring...I will give examples...
0
 
silemoneCommented:
but since string class is immutable, the best way to do this would be to use the stringbuilder class...
0
 
silemoneCommented:
StringBuilder s = new StringBuilder("astringoftext");
s[11] = 'q';
string sNew = s.ToString();

sNew is now "astringofteqt"


an example i found online...
0
 
silemoneCommented:
just in case,

The StringBuilder library is at System.Text.StringBuilder...
0
 
kwh3856Author Commented:
Thank you very much!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now