简体   繁体   中英

How do I make a Null character in Kotlin

In Java, one can use the escape sequence \\0 to represent the Null character

\\0 and \\0000 are not valid escape sequences in Kotlin, so I've been using a static java char and accessing that from Kotlin.

public class StringUtils{
  public static char escapeChar = '\0';
}

Is there a Null character literal, or a better way of doing this in Kotlin?

These options will work:

  • '\' (Unicode escape syntax, as described in the docs )
  • 0.toChar() ( conversions are optimized and have no function call overhead)
  • import java.lang.Character.MIN_VALUE as nullChar , then use nullChar ( renaming import )

I believe it must be '\' . Please visit this page for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM