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

String Manipulation

Status
Not open for further replies.

Nebooaw

Programmer
Jun 1, 2001
142
GB
Hi, if i have a sring containing values like...

Black, Green, Blue

how can i manipulate the string so it now reads...

Def1 = ''Black'' or Def1 = ''Green'' or Def1 = ''Blue''

and if the string only contains one value...

Def1 = ''Black''


Kindest regards
 
you can use the split function to separate the values from a for example comma separated string...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Thanks for replying, have you an example script which can split a string, add quotes before and after the value and rejoin the string?


kindest thanks.
 
Here you go Nebooaw:

strvalue = "black, red, blue"
strvalue = strvalue & ", "

do until (instr(strvalue, " ")=0)
firstspace=instr(strvalue, " ")
strcolour=left(strvalue, 1)
strcolour=strcolour-1
strvalue=mid(strvalue, firstspace+1)

'do stuff with strcolour here (put in array etc)

loop
 
strInp = "Black, Green, Blue"
strOut = "Def1=""" & Replace(strInp, ", ", """ Or Def1=""") & """

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Perfect, thanks for your example - all is clear now. Have got it sorted - works a treat!

Kindest thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top