Blog
Text - How to convert a character to its ASCII numeric value
November 28. 2021
There's no built-in function in Power Apps to convert a character to its ASCII value. This post describes how to carry out this task.
With Power Apps, the Char function takes a numeric ASCII code and returns the character representation.
http://powerappsguide.com/blog/post/how-to-use-char-function
Unfortunately, there's no built-in function to carry out the inverse of Char - that is, a function that returns the numeric ASCII code for an input character. It's useful to note that Excel VBA includes a function called ASC that carries out this task, and app builders familiar with Excel often search for a Power Apps equivalent.
To carry out this task, we need to write custom formula, and we can use the structure that's shown below.
With({inputString:"a"},We set inputString to the character to convert. As the screenshot beneath illustrates, the formula returns the correct ASCII code for the input character "a", which is 97.
LookUp(
ForAll(Sequence(255),
{Num:Value, Character:Char(Value)}
),
Character=inputString
).Num
)
How does this formula work?
The formula applies the ForAll function to generate a table with 2 columns - the numeric ASCII code and the corresponding character. The screenshot below highlights the return value of this section of formula.To retrieve the ASCII code that corresponds to a given input character, the outer call to LookUp retrieves the numeric value for the target character value.
Conclusion
Power Apps provides no built-in function to convert an input character to an ASCII code (ie, an Excel VBA ASC equivalent). This post described a formula to carry out this task.
- Categories:
- text
Related posts
- Text - How to truncate and add 3 dots / ellipsis to long label text
- How to split the URL parameter name and values from a hyperlink
- Numbers - How to Format Numbers with a Dollar Symbol the Right Way
- Text - How to extract email addresses that are formatted with angle brackets
- Text - The easiest way to copy text to the clipboard
- Text - How to split input strings by carriage return followed by the colon character
- Why doesn't the BeginWith, EndsWith, and Contains operators work as expected?