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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert spaces between two strings? 1

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
I have a first name and middle initial. Both put into seperate variables. I know the length of each string. I have to concatenate them together into a string that is limited to 16 characters with the middle initial being in the last position (16 character).

Example:

strfirst = "Apollo"
strmiddle = "6"

strFinal = "Apollo 6"

Any suggestions would be appreciated.

Thanks
 
strFinal = strFirst & Space(16 - Len(strfirst & strMiddle)) & strMiddle


I haven't tested it but something like that would work as lonng as strFirst & strMiddle concatenated never got over 16 characters.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Another way:
strFinal = Left(strFirst & Space(15), 15) & strMiddle

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Use PHV's. It as usual is better than mine because it avoids the boundary condition of Len(strFirst & strMiddle) > 16.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top