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

String question.

Status
Not open for further replies.

sborny

Technical User
Jun 29, 2001
157
0
0
GB
Hi All,

I know this is a silly question but I need to find out how to take the contents of a string, check for anything starting from the left until I find a space and then take what has been found and create a new string.

Hope that makes sense.

Cheers

S.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
use the mid() and instr() functions. Mid takes the part of the string you want, and instr() finds the space:

newString= mid(oldString, 1, instr(1, oldString, " ") - 1)

mid() uses the following:

string = mid([string], [start position], [lenght of new string])

Because instr() returns the position in the old string of the space, you therefore need toadd -1 at the end to return the bit before the space.

Good luck

BB
 
Or you could use Split and take the first array element. You may want to do a LTrim to your original text if you want to remove leading spaces first.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Hi Guys,

thanks for all your help.

What would I need to change if I wanted everything after the first space in a line.

Thanks

S.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
Use Split(Text1.Text," ") and the second element of the array resulting will be the bit after the first space.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
try:

newString= mid(oldString, instr(1, oldString, " ") + 1)

This takes the position of the first space, adds 1 and then uses this as the start of the new string. No length value is needed as it returning all the data to the right of the string.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top