Solved

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

Posted on 2008-09-29
5
256 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
Comment Utility
you could just use regular expression to substitute or substring...I will give examples...
0
 
LVL 21

Expert Comment

by:silemone
Comment Utility
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
Comment Utility
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
Comment Utility
just in case,

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

Author Closing Comment

by:kwh3856
Comment Utility
Thank you very much!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now