Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Parse

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hello,
I need to parse an AnsiString, I need to get the third character of a string eg:
String Number = "15432
char ParsedNumber = ???;//I need to populate this with the
third number (4 in this case)
any ideas?

Thanks
 
I believe that with AnsiString, the index will work. Just remember that AnsiStrings are one based instead of zero based (they start with the number 1 instead of 0).
Code:
String Number = "15432";
char ParsedNumber = (char)Number[3]; //I THINK this will work.

// If not, try 
String StrParsedNumber = Number[3];
int PNumber = StrToInt(StrParsedNumber); // You could put some error checking here
char ParsedNumber = PNumber;

I'm doing this from memory so use at your own risk. Good luck. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
I solved it myself, thanks though.
I just used a substring

//accesses the third index and the first number of that index
sParsedExerciseNumber = sParsedExerciseNumber.SubString(3,1)
 
That'll work, too ;-) James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top