Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin - Form feed character - Illegal escape: '\f'

Kotlin does not support the escape "\f" (Form Feed Character). So what is the proper way port "\f" from java to Kotlin?

Java:

String str = "\f"; // OK

Kotlin:

var str = "\f"  // Illegal escape: '\f'

Anyway, that looked like a bug to me because Kotlin and java should work well together.

like image 757
damphat Avatar asked May 25 '17 01:05

damphat


1 Answers

Use unicode escape \u000C. Kotlin doesn't support the \f escape. It isn't very widely used. - in fact I didn't realize that there is \f in Java until seeing your question.

I made a table on the Java and kotlin escape sequence:

Escape type|kotlin |java
\uXXXX      yes     yes
\XXX        no      yes         // this is Java octal escape.
\t          yes     yes
\b          yes     yes
\n          yes     yes
\r          yes     yes
\f          no      yes
\'          yes     yes
\"          yes     yes
\\          yes     yes
\$          yes     no          // Java just uses $

(Kotlin needs the escaped $ because string templates use $.)

like image 200
glee8e Avatar answered Sep 22 '22 13:09

glee8e