Skip to content

Instantly share code, notes, and snippets.

@daverix
Created July 25, 2018 09:13
Show Gist options
  • Save daverix/1c4f438c1924c7fc2dc79301a19ae043 to your computer and use it in GitHub Desktop.
Save daverix/1c4f438c1924c7fc2dc79301a19ae043 to your computer and use it in GitHub Desktop.
from camel case to screaming snake case
fun String.fromCamelCaseToScreamingSnakeCase(): String {
val builder = StringBuilder()
for(i in 0 until length) {
if(i > 0 && i < length-1 && this[i].isUpperCase())
builder.append("_")
builder.append(this[i].toUpperCase())
}
return builder.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment