I think that low level string handling in Kotlin is not very practical.
For instance, if I need remove 0 extra byte in the end, the shortest code is.
...removeSuffix(0.toChar().toString()...
I use this code because I’ve found a intermitent bug in reading some long text types in SQLite, that
which forces me to read the field as blob. In that case it returns to me an extra byte equal to 0.
val conteudo =String(c.getBlob(
c.getColumnIndex("Conteudo"))).removeSuffix(0.toChar().toString())
For adding some specific byte in a string, the code is.
var s:String
....
s = s + 0.toChar()
Code s = s + /u0000 is a right solution in Java, but not in Kotlin:
class Main {
public static void main(String[] args) {
String s = "whale\u0000";
Integer cod = (int) s.charAt(5);
System.out.println(cod);
}
}
It would be nice if extend escape \u usage for include prefix \u00.. like Java or create a new escape \c for enter a byte character. It’s also useful for network protocols.
For instance \c0B it would be a Vertical TAB character (#11) and \c00 it would be a #00 (Null character)
I could write in Kotlin:
var s = "Whale\c00"
It also would be useful a B suffix for Byte type. It is ugly compares an Integer with a Byte in Kotlin:
Yes,@ilya.gorbunov, you are right. I’m sorry for that. I’ve tested yesterday, maybe I was a little bit tired. So it is solved! However, B suffix in byte literal is not a bad idea…
Between the confusion of disregarding the prefix 0x and one make some confusion between 0x2B and 2B and the lack of isonomy of not accepting ALL numerical types as possible suffixes, I take the first option.
I get what you’re saying though, all primitive types should have a literal way of expressing them. Double, Float, Int, Char, String, and Long all have them, but not Byte?
Yes, @nbilyk It’s what I’m saying. About Double, you are right. I’m forgeting it… Yes, 2.0 is a Double literal, but it’s not explicitly what a person with little knowledge of Kotlin would interpret. So if all primitive number type has a suffix, why not double. String and Char type suffix is not necessary because ’ and ‘’ delimiter play this role. I prefer make programs for people that has no deep language understanding, including me, maybe, some years later.