Blog
Text - Examples of how to use the Char function, and a reference of ASCII codes
November 23. 2021
A very versatile function is the Char function. This post highlights example use case scenarios of how to utilise this function and provides a reference guide of ASCII codes.
The Char function is a very helpful function. It takes a numeric ASCII code and returns the character representation.
The official online documentation is very good, and describes how we can build a character map.
The official online documentation is very good, and describes how we can build a character map.
For Power Apps builders, a common requirement is to determine the ASCII number that corresponds to a given character. The following tables beneath provide a reference guide.
Basic Character Set
Here is the list of basic characters.
Num | Text | Num | Text | Num | Text |
---|---|---|---|---|---|
10 | Line Feed | 62 | > | 95 | _ |
12 | Form Feed | 63 | ? | 96 | ` |
13 | Carriage Return | 64 | @ | 97 | a |
32 | Space | 65 | A | 98 | b |
33 | ! | 66 | B | 99 | c |
34 | " | 67 | C | 100 | d |
35 | # | 68 | D | 101 | e |
36 | $ | 69 | E | 102 | f |
37 | % | 70 | F | 103 | g |
38 | & | 71 | G | 104 | h |
39 | ' | 72 | H | 105 | i |
40 | ( | 73 | I | 106 | j |
41 | ) | 74 | J | 107 | k |
42 | * | 75 | K | 108 | l |
43 | + | 76 | L | 109 | m |
44 | , | 77 | M | 110 | n |
45 | - | 78 | N | 111 | o |
46 | . | 79 | O | 112 | p |
47 | / | 80 | P | 113 | q |
48 | 0 | 81 | Q | 114 | r |
49 | 1 | 82 | R | 115 | s |
50 | 2 | 83 | S | 116 | t |
51 | 3 | 84 | T | 117 | u |
52 | 4 | 85 | U | 118 | v |
53 | 5 | 86 | V | 119 | w |
54 | 6 | 87 | W | 120 | x |
55 | 7 | 88 | X | 121 | y |
56 | 8 | 89 | Y | 122 | z |
57 | 9 | 90 | Z | 123 | { |
58 | : | 91 | [ | 124 | | |
59 | ; | 92 | \ | 125 | } |
60 | < | 93 | ] | 126 | ~ |
61 | = | 94 | ^ | 127 | DEL |
Extended Values
The table beneath shows the extended character set.
Num | Text | Num | Text | Num | Text |
---|---|---|---|---|---|
160 | Space (non-break) | 192 | À | 224 | à |
161 | ¡ | 193 | Á | 225 | á |
162 | ¢ | 194 | Â | 226 | â |
163 | £ | 195 | Ã | 227 | ã |
164 | ¤ | 196 | Ä | 228 | ä |
165 | ¥ | 197 | Å | 229 | å |
166 | ¦ | 198 | Æ | 230 | æ |
167 | § | 199 | Ç | 231 | ç |
168 | ¨ | 200 | È | 232 | è |
169 | © | 201 | É | 233 | é |
170 | ª | 202 | Ê | 234 | ê |
171 | « | 203 | Ë | 235 | ë |
172 | ¬ | 204 | Ì | 236 | ì |
173 | | 205 | Í | 237 | í |
174 | ® | 206 | Î | 238 | î |
175 | ¯ | 207 | Ï | 239 | ï |
176 | ° | 208 | Ð | 240 | ð |
177 | ± | 209 | Ñ | 241 | ñ |
178 | ² | 210 | Ò | 242 | ò |
179 | ³ | 211 | Ó | 243 | ó |
180 | ´ | 212 | Ô | 244 | ô |
181 | µ | 213 | Õ | 245 | õ |
182 | ¶ | 214 | Ö | 246 | ö |
183 | · | 215 | × | 247 | ÷ |
184 | ¸ | 216 | Ø | 248 | ø |
185 | ¹ | 217 | Ù | 249 | ù |
186 | º | 218 | Ú | 250 | ú |
187 | » | 219 | Û | 251 | û |
188 | ¼ | 220 | Ü | 252 | ü |
189 | ½ | 221 | Ý | 253 | ý |
190 | ¾ | 222 | Þ | 254 | þ |
191 | ¿ | 223 | ß | 255 | ÿ |
What are some use case scenarios for Char?
What exactly can we do with the Char function? The most common scenarios include the following:1. Adding line breaks in formula
When we build text with formula, we can call Char(10) and Char(13) to insert line breaks.Char(10) is the Line Feed character and Char(13) is the Carriage Return character. Historically, the Line Feed character moves the insertion point to the next line, but doesn't return the cursor to left-most part of the screen. The Carriage Return character returns the cursor to the left.
In practice, it doesn't make a noticeable difference if we use either Char(13) or Char(10) to add line breaks to text on a Power Apps screen. However, it's generally best practice to insert line breaks by inserting Char(13) or Char(10), most notably in cases where we build construct text for use in applications outside of Power Apps.
As an example, let's suppose we want to display a label that summarises text box entries on a screen. We can combine the value from the text input boxes and append lines between each field like so:
2. Displaying special characters
We can call the Char function to display special characters - for example, mathematical symbols, fractional digits, the copyright symbol etc. Whilst the HTML text control provides a simple way to display special characters, The Char function offers a viable way to build text through formula, and to display the output in places such as buttons, or data table headers. The screenshot beneath demonstrates how to display the 'squared' symbol.
3. Adding non-breaking spaces in formula
Power Apps renders as HTML in a web browser. The behaviour that is familiar to many web developers, is that HTML prevents consecutive whitespace characters by collapsing multiple spaces into a single space.
Let's take the example of a button control. If we set button text to "Save Record" (note the multiple spaces), the button control collapses all consecutive spaces to a single space.
To display multiple consecutive spaces, we can insert non-breaking space characters ( which is Char(160)), as highlighted in the screenshot beneath.
Note that in the canvas app designer, if we click the visual designer, edit the button text, and enter space characters, the designer automatically inserts non-breaking spaces. If we enter spaces through formula or the text property however, Power Apps inserts breaking spaces instead.