All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dankito.utils.extensions.StringExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.0.20
Show newest version
package net.dankito.utils.extensions


fun String.ofMaxLength(maxLength: Int): String {
    if(this.length > maxLength && maxLength > 0) {
        return this.substring(0, maxLength)
    }

    return this
}


fun String.countOccurrences(charToFind: Char): Int {
    var countOccurrences = 0

    for (char in this) {
        if (char == charToFind) {
            countOccurrences++
        }
    }

    return countOccurrences
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy