Created
July 25, 2018 09:13
-
-
Save daverix/1c4f438c1924c7fc2dc79301a19ae043 to your computer and use it in GitHub Desktop.
from camel case to screaming snake case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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