Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine string variable type
#1
Hello everyone,

I need to make a judgment, but can't get the right result, I hope someone can point out the mistake. Thanks in advance

If s is a number or variable name, out s, else out "s"

 Expected output:
 Case 1    a2
 Case 2   _b
 Case 3    3
 
 Case 4   "2a"
 Case 5   "C:\Users\Administrator\Desktop\test.txt"
 Case 6   "C:\Users\Administrator\Desktop"
 Case 7   "世界"


Macro q1
Code:
Copy      Help
;str s="a2" ;;Case 1
;str s="_b" ;;Case 2
;str s="3" ;;Case 3

str s="2a" ;;Case 4
;str s="C:\Users\Administrator\Desktop\test.txt" ;;Case 5
;str s="C:\Users\Administrator\Desktop" ;;Case 6
;str s="世界" ;;Case 7

if(findrx(s "^[a-zA-Z_][a-zA-Z0-9_]*") or findrx(s "\d+"))
,out s
else
,out F"''{s}''"    

;Expected output:
;Case 1    a2
;Case 2   _b
;Case 3    3
;
;Case 4   "2a"
;Case 5   "C:\Users\Administrator\Desktop\test.txt"
;Case 6   "C:\Users\Administrator\Desktop"
;Case 7   "世界"


Messages In This Thread
Determine string variable type - by macman - 01-12-2021, 01:51 AM
RE: Determine string variable type - by Kevin - 01-12-2021, 04:07 AM
RE: Determine string variable type - by macman - 01-12-2021, 05:29 AM
RE: Determine string variable type - by Kevin - 01-12-2021, 06:10 AM
RE: Determine string variable type - by macman - 01-12-2021, 07:14 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)