How to do a script that would replace a letter with it's number (a - 01; b - 02; c-03 and so on)? Should I use Loop? I know there is a hard way to do it one-by-one with pure StringReplace, but copy-paste is a very dirty and awful thing to do in code.
Any help would be appreciated!
Replace letter with it's number Topic is solved
Replace letter with it's number
Твой софт - говно!
-
- Posts: 92
- Joined: 28 Mar 2016, 07:59
Re: Replace letter with it's number
depends on how you want it to happen, hotkey? triggered by input into an edit field? either way, the below will help start your brain.
Code: Select all
ALPHA_NUMBERS := "A:01,B:02,C:03,D:04,E:05,F:06,G:07,H:08,I:09,J:10,K:11,L:12,M:13,N:14,O:15,P:16,Q:17,R:18,S:19,T:20,U:21,V:22,W:23,X:24,Y:25,Z:26"
inputVar := "D"
loop parse, ALPHA_NUMBERS, `,
{
StringSplit array, A_LoopField, `:
if (inputVar = array1) {
MsgBox % "the number is " array2
break
}
}
ExitApp
Re: Replace letter with it's number
I would do it like this.
Code: Select all
MsgBox, % CharToNum("abcdefg")
MsgBox, % CharToNum("ABCDEFG")
CharToNum(String){
a := Ord("a") - 1
for index, char in StrSplit(String){
res .= Format("{:02}", Ord(Format("{:L}", char)) - a)
}
return res
}
Please excuse my spelling I am dyslexic.
Re: Replace letter with it's number Topic is solved
another example
Code: Select all
a=ABCZYX
loop,parse,a,
Z .= substr(0 Asc(A_LoopField)-64,-1)
msgbox,%z%
Re: Replace letter with it's number
Dammit, you guys are awesome! Thank you everyone!
P. S. I like Garry's example more than others as it's super simple
P. S. I like Garry's example more than others as it's super simple
Твой софт - говно!
Re: Replace letter with it's number
user 'Capn Odin' considered Upper /Lower
so script also not so short ....
so script also not so short ....
Code: Select all
a=AbCzYX
loop,parse,a,
{
if (asc(a_loopfield) > 64 and asc(a_loopfield) < 91)
Z .= substr(0 Asc(A_LoopField)-64,-1)
if (asc(a_loopfield) > 96 and asc(a_loopfield) < 123)
Z .= substr(0 Asc(A_LoopField)-96,-1)
}
msgbox,%z%
return
Who is online
Users browsing this forum: bobstoner289, Ralf_Reddings200244 and 303 guests