Page 1 of 1
Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Mon Mar 20, 2017 3:35 pm
by DR White
Is the an easy way to Convert 1 (540) 444-2045 to 15404442045?
If there isn't, no big deal.
I can use a several Offset functions to clean it up, but thought there might be an easier way.
Thanks,
David
Re: Convert 1 (540) 444-2045 to 15404442045?
Posted: Mon Mar 20, 2017 3:56 pm
by LiveCode_Panos
Hi DR White,
What about this?
Code: Select all
on mouseUp
answer myFun("1 (540) 444-2045")
end mouseUp
function myFun pIn
local tOut
repeat for each char tChar in pIn
if isNumber(tChar) then
put tChar after tOut
end if
end repeat
return tOut
end myFun
Best,
Panos
--
Re: Convert 1 (540) 444-2045 to 15404442045?
Posted: Mon Mar 20, 2017 4:12 pm
by DR White
Panos,
That works GREAT!
Thanks,
David
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Tue Mar 21, 2017 3:35 am
by dunbarx
Just for a different way to think about stuff:
Code: Select all
replace space with empty in yourString
replace "(" with empty in yourString
replace ")" with empty in yourString
replace "-" with empty in yourString
Craig Newman
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Tue Mar 21, 2017 8:52 am
by AndyP
In one line
Code: Select all
put replacetext("1 (540) 444-2045","[^0-9]","")
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Thu Mar 23, 2017 1:36 pm
by DR White
Craig and Andy,
Thanks for the other solutions for converting mixed text to numbers.
Andy,
Where in the world to you find the option [^0-9] for replacetext?
When I use:
put "1 (540) 444-2045" into Test
put replacetext(Test,"[^0-9]","")
The string Test has not been converted>
Thanks,
David
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Thu Mar 23, 2017 2:11 pm
by Thierry
DR White wrote:
When I use:
put "1 (540) 444-2045" into Test
put replacetext(Test,"[^0-9]","")
The string Test has not been converted>
Hi David,
the converted text is the output of the function replacetext()
Therefore, try this:
Code: Select all
put "1 (540) 444-2045" into Test
put replacetext(Test,"[^0-9]","") into Test
put Test
HTH,
Thierry
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Thu Mar 23, 2017 2:16 pm
by Klaus
Hi David,
DR White wrote:When I use:
Code: Select all
put "1 (540) 444-2045" into Test
put replacetext(Test,"[^0-9]","")
The string Test has not been converted
"replacetext" is a function and does not modify its parameters!
But its OUTPUT is what you need!
Code: Select all
...
put "1 (540) 444-2045" into Test
put replacetext(Test,"[^0-9]","") into TEST2
answer TEST2
## = converted string!
...
Best
Klaus
P.S.
Ah, Thierry beat my by a couple of minutes

Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Thu Mar 23, 2017 2:56 pm
by DR White
Thanks Klaus and Thierry!
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Thu Mar 23, 2017 8:20 pm
by DR White
Thierry,
Where did you find the info to use "[^0-9]"? in the replacementtext function?
Thanks,
David
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Fri Mar 24, 2017 7:58 am
by Thierry
DR White wrote:Thierry,
Where did you find the info to use "[^0-9]"? in the replacementtext function?
David,
This one is a copied/pasted of Andy's post
More seriously must be some information in the dictionary,
plus a RegexBuilder plugin
IDE Menu -> Development->Plugins->RegexBuilder
and I remember about a very simple stack with more details about regex
in sample stacks delivered with the IDE: still there?
The net is full of information about regex
but be careful there are a lot of different flavors of regex,
depending mainly of the regex engine and the language embedding it.
Kind regards,
Thierry
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Fri Mar 24, 2017 9:56 am
by AndyP
Initially I did a Google search with "regex dictionary exclude non numbers" which came up with lots of hits using this "[^0-9]".
eg.
http://stackoverflow.com/questions/3055 ... -or-period
Then I found some good explanation sources for Regex here
http://www.visca.com/regexdict/tutorial.html
http://www.pnotepad.org/docs/search/reg ... pressions/
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Fri Mar 24, 2017 9:58 am
by SparkOut
Thierry fell into the regex barrel when he was a baby, and had to eat his way through the whole lot to save himself from suffocation.
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Posted: Fri Mar 24, 2017 10:24 am
by Thierry
SparkOut wrote:Thierry fell into the regex barrel when he was a baby,
and had to eat his way through the whole lot to save himself from suffocation.
the truth is, at this time, I had one foot in a regex barrel
and the other one in the Hypercard barrel!
Enjoy your day
