Special characters in Ruby


#1

Hello,

In the exercises, for example :

9.’.upcase’ & ‘.downcase’

we are asked to use our name for the exercise. However my name includes the special character “é”. If I enter it, it automatically remove the letter.
I can use another name for the exercise, but I would like to know if there is a way to use special characters in Ruby, if we need them to appear on screen ?

Thank you !


#2

Whether an accented character is considered as a character or not,
depends on a feature called “locale”. This is not so much Ruby-specific;
it applies to virtually all programming languages.

Since you are still a beginner with Ruby, and locale is an advanced
topic, you spare yourself a lot of headaches if you just stick with
ASCII letters. If you are interested in the Ruby support for this, have
a look at https://ruby-doc.org/core-2.4.1//String.html#method-i-downcase

Ronald


#3

Thanks for the answer :slight_smile:

It was just out of curiosity, because if I plan to write strings in my language, I will need those letters !


#4

You can use all the strings you like. The problem is just character
classification, i.e. to decide what characters comprise i.e. a digit or
a letter. This is by far not obvious.

BTW, when you start processing strings outside the ASCII realm, you will
also have to care about the encoding. Inside Ruby, everything is UTF-8
(unless you explicitly say differently - you can choose the encoding for
each string individually, if you want), but when you are reading or
writing files, you need to be aware that they might be in different
encodings.

Ronald


#5

Thank you for all the explanations Ronald, I’ll keep this thread somewhere for when I am a bit more advanced !


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.