Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I don't think testimonials would have enticed me to become a member, or even use the site for that matter. I use the site for a learning experience..."

Geography

Where in the world do Tek-Tips members come from?

Seperating an AnsiString by a space

cyprus106 (Programmer)
6 Oct 07 13:19
I've got a String that's seperated in teh middle by a space. (i.e., It's a First and Last name in a combo box) I've got to split the first name in one string and the last name in another.
I swear, I used to know how to do this, but I'm rusty. Somebody that knows how to do this please help, it's worth a star!

Thanks much,
-M

Cyprus

2ffat (Programmer)
8 Oct 07 7:44
Off the top of my head:

CODE

AnsiString NameStr = "James Cottingham";
int SpacePlaceInt = NameStr.Pos(" ");// Should be 6

Of course, you may want to make certain that you don't have spaces on the front or the end, too. Or you might want to check for multiple spaces if, for example, they put in their middle initial.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!

cyprus106 (Programmer)
8 Oct 07 19:42
Wait, I'm still slightly confused. I wanted "James" and "Cottingham" in two seperate Strings? I still don't know how to get the names with what you gave me??

Cyprus

2ffat (Programmer)
9 Oct 07 7:40

CODE

AnsiString NameStr = "James Cottingham";
int StrLenInt = NameStr.Length();
int SpacePlaceInt = NameStr.Pos(" ");
AnsiString FirstNameStr = NameStr.SubString(1, SpacePlaceInt - 1); //AnsiStrings always start with 1 and not 0
AnsiString LastNameStr = NameStr.SubString(SpacePlaceInt + 1, StrLenInt);

Play with it a little as I'm doing this from memory.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close