Welcome Guest

Pages: 1
Convert character to number
UKenGBPostJune 16, 2022, 15:36
Advanced
Posts: 57
Registered:
April 30, 2020, 09:36
Normal topicConvert character to number

I need to be able to convert letters of the alphabet [A-Z] to numbers [1-26] respectively. It will be just a single char I need to convert to its appropriate number. So an 'A' needs to be converted to 1, a 'J' needs to be converted to 10, etc.

How can I do that in Yate, without a long series of 'tests' and 'if true' statements.

Ideally, I want a case/switch type of construct, but I know Yate doesn't have that. So I was thinking of converting the char to it's ascii number and then a simple subtraction would get what I need. However I cannot see a way to get ascii numbers from a character.

I could come up with some other ways, but all rather inefficient. Any suggestions as to how to accomplish this?

2MR2PostJune 17, 2022, 07:28
Avatar photo
Administrator
Posts: 2085
Registered:
August 23, 2012, 19:27
Normal topicConvert character to number

Set named variable 'Characters of Interest' to "/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Set named variable 'Result' to the index of "\<Char>" in named variable 'Characters of Interest'

The above will work assuming named variable Char contains a single character in the range of A - Z

The / at the start of 'Characters of interest' is to bump the index of A to 1.

2MR2PostJune 17, 2022, 19:20
Avatar photo
Administrator
Posts: 2085
Registered:
August 23, 2012, 19:27
Normal topicConvert character to number

v6.10.3 will have two new functions available in the Make Numeric statement:

As Alphabetic Index will return a value of 1 through 26 if the first character in the source is in the range of A through Z (case and diacritic insensitive), otherwise 0. As Unicode Character Value returns the Unicode value of the first character in the source. If the source is empty, -1 is returned.

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.016 seconds.