Question : replacing/deleting spaces in a string vfp

Hi: have some text coming into vfp. Sometimes the text has two spaces and for reasons I cannot work out when the text passes through other programs (eg excel) the extra space is taken out. The format is crucial; and I want better control over the text  so I would like to either delete the second space or - if easier - replace all spaces with (say) a comma. Is this possible in vfp? Or both?! Thanks!

Answer : replacing/deleting spaces in a string vfp

You can also look at VFP help ... :-)

To replace two spaces by one space:
STRTRAN(text, "  ", " ")

To replace all spaces by commas:
CHRTRAN(text, " ", ",")

To replace many spaces by one space:
DO WHILE LEN(text) <> LEN(STRTRAN(text, "  ", " "))
  text = STRTRAN(text, "  ", " ")
ENDDO

You could also find useful functions GETWORDCOUNT() and GETWORDNUM() which are not listed in above link.
Random Solutions  
 
programming4us programming4us