Solved

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

Posted on 2008-09-29
5
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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