21

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.

damphat
  • 18,246
  • 8
  • 45
  • 59

1 Answers1

28

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 $.)

glee8e
  • 6,180
  • 4
  • 31
  • 51