Hi
I have a requirements to convert a string of alphabets to numbers. For example the string could be “ABC” this needs to be converted to 111213. I think using case statement may work but does anyone else have a suggestion?
Thanks in advance.
Hi
I have a requirements to convert a string of alphabets to numbers. For example the string could be “ABC” this needs to be converted to 111213. I think using case statement may work but does anyone else have a suggestion?
Thanks in advance.
Subject: @replacesubstring
Subject: Converting Alphabets to Numbers
Effendi, based on your example, it’s difficult to determine what algorithm you have in mind for converting the alphabetic characters to numbers.
It appears from your example that A = 11, B = 12 and C = 13, but that could be an incorrect assumption. Could you post how the translation will be done, then perhaps we can assist you with how to code it?
Subject: RE: Converting Alphabets to Numbers
Jerry
Thanks fir taking the time to look at this. In my example you are right, A=11, B=12, C=13 etc.
I have to traslate a 8-character string to numbers. It could be all numerical or could be a mix of numeric of alphabets.
For example it could be 12345678 then it will turn out to be 12345678
or it could be ABCDEFGH resulting in
111213141516161718
or it could be A1234567 resulting in
111234567
Thanks once again.
Subject: RE: Converting Alphabets to Numbers
There are probably a number of ways. One might be:
str := @ReplaceSubstring(@UpperCase(str); “A”:“B”:“C”:…“Z”; “11”:“12”:“13”…“36”);
and another might be to use @Transform, if you can figure out hot to explode the list into separate characters. You could also use an @For loop, but I think the @ReplaceSubstring would be faster. Oh yes, in case it isn’t obvious, you need to fill in all twenty six letters and numbers, not just the ones I did above.
Subject: RE: Converting Alphabets to Numbers
Thanks. Both options are useful.
Subject: RE: Converting Alphabets to Numbers
Effendi, since your original post mentioned using the Case statement, it sounded like you wanted to do this in script. If so, try this:
Function StrgCnvt (parm As String) As String
x$ = ""
y$ = Ucase$(parm)
For j% = 1 To Len(y$)
Char$ = Mid$(y$,j%,1)
If Asc(Char$) >= 65 And Asc(Char$) <= 90 Then
Char$ = Cstr(Asc(Char$) - 54)
End If
x$ = x$ & Char$
Next
StrgCnvt = x$
End Function
Subject: *Good catch about the script.
Subject: RE: Converting Alphabets to Numbers
Intrigueing request - out of curiousity, could you give an example in which this would be used?