1. ## string puzzle

Can any one offer a pointer to solving this little prob.

Have a string field that contains a list of names (various numbers, seperated by a comma) Eg.

Record 1: Mike, Alan, John
Record 2: Tony
Record 3: Emma, Marrie
Record 4: John, Peter, David, Andrew

I want to change the field so it contains the following

Record 1: Mike, Alan and John
Record 2: Tony
Record 3: Emma and Marrie
Record 4: John, Peter, David and Andrew

Any ideas appreciated, Thanks!

2. ## RE: string puzzle

strng="Mike"
?if(at(",",strng)=0,strng,*reverse(strtran(*reverse(strng),",","dna ",1,1)))
= "Mike"

strng = "John, Peter, David, Andrew"
?if(at(",",strng)=0,strng,*reverse(strtran(*reverse(strng),",","dna ",1,1)))
= "John, Peter, David and Andrew"

3. ## RE: string puzzle

Another approach:

teststring = "Bill, John, Mary"

?occurs(",",teststring)
= 2

?at(",",teststring,2)
= 11

?substr(teststring,1,11)
= "Bill, John,"

?len(trim(teststring))
= 16

?right(teststring,16-11)
= " Mary"

?if(occurs(",",teststring)= 0, teststring, substr(teststring,1,at(",",teststring,occurs(",",teststring)))+" and" + right(teststring,len(trim(teststring))- at(",",teststring,occurs(",",teststring))))
= "Bill, John, and Mary"

-- tom

4. ## RE: string puzzle

teststring = "John, Peter, David, Andrew"
? stritran(teststring,","," and",w_count(teststring,", ")-1,1)
= "John, Peter, David and Andrew"

5. ## RE: string puzzle

Wow,

Thanks for the varied response (always fascinating to see how others approach problems with the same tools)

After the initial hour of mental block I came up with this (about 5mins after submitting the cry for help!)

left(teststring,at(',',teststring,-1)-1)+' and'+right(teststring,len(teststring)-at(',',teststring,-1))

But looks like theres some much shorter and cleaner methods than this, thank you for the input as always.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•