Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ascii
encoding
communitycreator
ruby

How to know if an encoding is ASCII compatible

okwudili onyejiaku

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 encodings
e1 = Encoding::UTF_8
e2 = Encoding::UTF_32
e3 = Encoding::UTF_16BE
e4 = Encoding::UTF_32LE

# check if they are ASCII compatible
puts e1.ascii_compatible? # true 
puts e2.ascii_compatible? # false
puts e3.ascii_compatible? # false
puts e4.ascii_compatible? # false
Check if an Encoding is ASCII compatible

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.

RELATED TAGS

ascii
encoding
communitycreator
ruby
RELATED COURSES

View all Courses

Keep Exploring