Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Macro for clipboard number formatting
#1
Hello,

I am trying to make an adjustment to a macro to remove a 1 or 0 if it's at the start of a string of numbers in my clipboard. Currently I use this macro below in the quote.

It's for formatting phone numbers, because too many things I work with don't use any data validation. 

So if someone puts in 15551234567 I want to get only 5551234567 without removing or subbing out the 1 in the middle. Any suggestions?
 
Quote:str s
;get clipboard text
s.getclip ;;or s.getsel to copy selection

;as an example, convert find space then replace it with nothing
s.findreplace(" " "")
s.findreplace("-" "")
s.findreplace("." "")
s.findreplace("(" "")
s.findreplace(")" "")
s.findreplace("\" "")
s.findreplace("/" "")
;place it to the clipboard
s.setclip ;;or s.setsel to paste directly
#2
Try this:
Macro Macro8
Code:
Copy      Help
out
str s
s.getclip
int i
str result
if (s[0]='0' || s[0]='1')
,for i 1 len(s)
,,_s.format("%c" s[i])
,,result += _s
else
,result = s
result.setclip
out "%s" result
Code:
Copy      Help
 
#3
Macro Macro3171
Code:
Copy      Help
str rx =
;^[01](\d+)$
if(!s.replacerx(rx "$1")) ret
out s
#4
Both work! I'm using @Gigtaras' because it's shorter <3 Thank you both!

Actually scratch that I am now using both sets of code in different macros for different macro tasks <3


Forum Jump:


Users browsing this thread: 1 Guest(s)