Convert 1 (540) 444-2045 to 15404442045? - Solved
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Convert 1 (540) 444-2045 to 15404442045? - Solved
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
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
Last edited by DR White on Mon Mar 20, 2017 4:12 pm, edited 1 time in total.
-
- Livecode Staff Member
- Posts: 818
- Joined: Fri Feb 06, 2015 4:03 pm
Re: Convert 1 (540) 444-2045 to 15404442045?
Hi DR White,
What about this?
Best,
Panos
--
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
Panos
--
Re: Convert 1 (540) 444-2045 to 15404442045?
Panos,
That works GREAT!
Thanks,
David
That works GREAT!
Thanks,
David
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Just for a different way to think about stuff:
Craig Newman
Code: Select all
replace space with empty in yourString
replace "(" with empty in yourString
replace ")" with empty in yourString
replace "-" with empty in yourString
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
In one line
Code: Select all
put replacetext("1 (540) 444-2045","[^0-9]","")
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
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
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
Hi David,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>
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
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Hi David,
But its OUTPUT is what you need!
Best
Klaus
P.S.
Ah, Thierry beat my by a couple of minutes
"replacetext" is a function and does not modify its parameters!DR White wrote:When I use:The string Test has not been convertedCode: Select all
put "1 (540) 444-2045" into Test put replacetext(Test,"[^0-9]","")
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!
...
Klaus
P.S.
Ah, Thierry beat my by a couple of minutes
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Thanks Klaus and Thierry!
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
Thierry,
Where did you find the info to use "[^0-9]"? in the replacementtext function?
Thanks,
David
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
David,DR White wrote:Thierry,
Where did you find the info to use "[^0-9]"? in the replacementtext function?
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
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/
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/
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Convert 1 (540) 444-2045 to 15404442045? - Solved
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
the truth is, at this time, I had one foot in a regex barrelSparkOut 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.
and the other one in the Hypercard barrel!
Enjoy your day
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!