Created
October 23, 2017 20:42
-
-
Save voghDev/70e80837681c1e330403fe7a125cb447 to your computer and use it in GitHub Desktop.
Kotlin Function that determines if a string starts with an upper-case letter [A-Z]
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.startsWithUppercaseLetter() : Boolean { | |
| return this.matches(Regex("[A-Z]{1}.*")) | |
| } | |
| // Very simple test to verify previous function output | |
| @Test | |
| fun `should calculate properly if some strings start with an uppercase letter`() { | |
| assertFalse("lowerCaseString".startsWithUppercaseLetter()) | |
| assertTrue("This is a String".startsWithUppercaseLetter()) | |
| assertFalse("1234 Starts with a number".startsWithUppercaseLetter()) | |
| assertFalse("".startsWithUppercaseLetter()) | |
| assertFalse(" ".startsWithUppercaseLetter()) | |
| assertFalse("_".startsWithUppercaseLetter()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment