How to know if an encoding is ASCII compatible
Overview
An encoding is ASCII compatible if it is a standard for electronic communication. To know if an encoding is ASCII compatible, we can use the ascii_compatible? property.
Syntax
encoding.ascii_compatible?
Return value
The value returned is a boolean. A true is returned if the encoding is ASCII compatible. Otherwise, false is returned.
Example
# get some encodingse1 = Encoding::UTF_8e2 = Encoding::UTF_32e3 = Encoding::UTF_16BEe4 = Encoding::UTF_32LE# check if they are ASCII compatibleputs e1.ascii_compatible? # trueputs e2.ascii_compatible? # falseputs e3.ascii_compatible? # falseputs e4.ascii_compatible? # false
Explanation
- Line 2–5: We get some encodings.
- Line 8–11: We check if the encodings are ASCII compatible. Then we print the result to the console.