I have a string like
var str = "AbCdEfGhIj"
that i want to toggle each character casing, that is,
convert it to var str = "aBcDeFgHiJ"
i am currently using this code below
val bytes = "HEllo WoRLd".toByteArray()
// Swap upper and lower case letters.
for (i in bytes.indices) {
if (bytes[i] >= 'A'.toByte() && bytes[i] <= 'Z'.toByte())
bytes[i] = ('a'.toInt() + (bytes[i] - 'A'.toByte())).toByte()
else if (bytes[i] >= 'a'.toByte() && bytes[i] <= 'z'.toByte())
bytes[i] = ('A'.toInt() + (bytes[i] - 'a'.toByte())).toByte()
}
System.out.print(String(bytes)) // heLLO wOrlD
Wondering if there's a regex that can do this