[android-components](../../index.md) / [mozilla.components.support.ktx.kotlin](../index.md) / [kotlin.String](index.md) / [tryGetHostFromUrl](./try-get-host-from-url.md)

# tryGetHostFromUrl

`fun `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`.tryGetHostFromUrl(): `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) [(source)](https://github.com/mozilla-mobile/android-components/blob/master/components/support/ktx/src/main/java/mozilla/components/support/ktx/kotlin/String.kt#L103)

Tries to parse and get host part if this [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) is valid URL.
Otherwise returns the string.

