Page 1 of 1

replacePointsInString

Posted: Wed Feb 23, 2011 11:01 am
by jmburnod
Hi All,
I want replace all points (point = ".") of a string.
I tried this but it not work and i dont undertand why

Code: Select all

on testReplacePoint pMet
   put ".aa,bb,cc." into MyString
   if pMet = 1 then
      put "." into unSC --•• test1 dont work
   end if
   if pMet = 2 then
      put numtochar(46) into unSC --•• test2 dont work
   end if
   put replacetext(MyString,unSC,space) into LeT
   put empty into TheCTN
   put the num of chars of LeT
   repeat for each char UnC in LeT
      put chartonum(Unc)&"," after TheCTN
   end repeat
   delete last char of TheCTN
   put LeT&return&TheCTN into msg
end testReplacePoint
the result is

32,32,32,32,32,32,32,32,32,32
Before you jump on your keyboard i found an other curious way.
Maeby you have one more elegant.

Code: Select all

on testReplacePoint2
   put ".aa,bb,cc." into MyString
   put empty into MyString2
   set the itemdel to "."
   repeat for each item myitem in MyString
      put myitem after MyString2
   end repeat
   set the itemdel to ","
   put MyString&return&MyString2 into msg
end testReplacePoint2
The result is correct
.aa,bb,cc.
aa,bb,cc
Someone have an explanation for the first case ?

All the best

Jean-Marc

Re: replacePointsInString

Posted: Wed Feb 23, 2011 12:33 pm
by Dixie
Hi Jean-Marc..

Code: Select all

on mouseUp
   put ".aa,bb,cc." into stringToChange
   replace "." with empty in stringToChange
   put stringToChange
end mouseUp
take care

Dixie

Re: replacePointsInString

Posted: Wed Feb 23, 2011 1:06 pm
by jmburnod
Hi Dixie,
take care
Ok i'm going to the garden

Jean-Marc