Blog

Text - Examples of how to use the Char function, and a reference of ASCII codes

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.


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.

NumTextNumTextNumText
10Line Feed62>95_
12Form Feed63?96`
13Carriage Return64@97a
32Space65A98b
33!66B99c
34"67C100d
35#68D101e
36$69E102f
37%70F103g
38&71G104h
39'72H105i
40(73I106j
41)74J107k
42*75K108l
43+76L109m
44,77M110n
45-78N111o
46.79O112p
47/80P113q
48081Q114r
49182R115s
50283S116t
51384T117u
52485U118v
53586V119w
54687W120x
55788X121y
56889Y122z
57990Z123{
58:91[124|
59;92\125}
60<93]126~
61=94^127DEL

Extended Values

The table beneath shows the extended character set.

NumTextNumTextNumText
160Space (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õ
182214Ö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.

Conclusion

This post summarised the usage of the Char function and provided some practical examples of how to utilise the function.