library / org.akop.kotx.ext.basic / kotlin.String

Extensions for kotlin.String

compareTo

fun String?.compareTo(other: String?): Int

Compares two nullable String objects.

htmlAsSpannable

fun String.htmlAsSpannable(tagHandler: TagHandler? = null): CharSequence?

Converts HTML text to a formatted string as performed by Html.fromHtml. Suppresses any exceptions.

htmlEncode

fun String.htmlEncode(): String

HTML-encodes a string by calling TextUtils.htmlEncode.

toColorInt

fun String.toColorInt(): Int

Uses Color.parseColor to convert string representation of a color (such as "#cedefa") to integer representation.

toColorIntOrNull

fun String.toColorIntOrNull(): Int?

Uses Color.parseColor to convert string representation of a color to integer, or null if string can't be parsed.

toURL

fun String.toURL(context: URL? = null): URL

Converts a String to URL, with an optional URL context.

toURLOrNull

fun String.toURLOrNull(context: URL? = null): URL?

Converts a String to URL, with an optional URL context returning null if string cannot be parsed.

toUri

fun String.toUri(): Uri

Converts a String to Uri by calling Uri.parse.

toUriOrNull

fun String.toUriOrNull(): Uri?

Converts a String to Uri by calling Uri.parse; returning null if the string cannot be parsed.

urlDecode

fun String.urlDecode(encoding: String = "UTF-8"): String

Decodes a URL-encoded string by calling URLDecoder.decode.

urlEncode

fun String.urlEncode(encoding: String = "UTF-8"): String

URL-encodes a string by calling URLEncoder.encode.