- Learning Scala Programming
- Vikash Sharma
- 205字
- 2021-06-30 19:07:49
Character literals
What if you want to break down some words and spaces into separate characters? If you do so, you're creating Character literals. We represent Character literals in single quotes. Any Unicode character or escape sequence can be represented as a Character literal. What's an escape sequence, by the way? Let's take this backslash for example. If we try this:
scala> val aChar = '\'
<console>:1: error: unclosed character literal
val aChar = '\'
This will not work at all, because this '\' is an escape character. By definition, an escape sequence or character is something that does not represent itself in String or Character literal. To define these characters, we use this sequence:
scala> val doublequotes = "\""
doublequotes: String = "
scala> val aString = doublequotes + "treatme a string" + doublequotes
aString: String = "treatme a string"
In the preceding code, we used our doublequotes as prefix and suffix to our string treatme a string, and get a response.
We've a list of escape sequence characters shown in the following table:

You can also use the hex code to represent a Character literal, but we need to put a \u preceding it:
scala> val c = '\u0101'
c: Char = ā
- C++案例趣學(xué)
- Python爬蟲開發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Rust Cookbook
- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Learning Selenium Testing Tools(Third Edition)
- HTML5+CSS3網(wǎng)頁設(shè)計
- BeagleBone Black Cookbook
- Mastering Linux Security and Hardening
- 21天學(xué)通C++(第5版)
- App Inventor少兒趣味編程動手做
- Visual C++從入門到精通(第2版)
- Tableau Dashboard Cookbook
- HTML并不簡單:Web前端開發(fā)精進(jìn)秘籍
- Python人工智能項(xiàng)目實(shí)戰(zhàn)
- LiveCode Mobile Development Hotshot