I am currently working on a task and wondering how I can achieve this implementation. I have this unique URL, fake url here https://home.ab.home.team/?buycode=12345678
what I am trying to print out, is the first home
after //
not the home
after the .ab
let's call it company code. I know in a Uri, I can get the authority which as per documentation it returns this entire part home.ab.home.team
My use case though is I only want to print out home
based on unique companies and situation we support. How can I achieve this. This is what I have so far.
sealed class Link {
data class Buy(val companyCode: String?) : Link()
}
my function getCode(uri)
now where I am trying to get home
is where I am stuck
how can I get and return the home without the other part?
private fun getCode(uri: Uri): String{
// todo
}
CodePudding user response:
Try this code:
private fun getCode(uri: Uri): String{
val s = uri.toString()
val start = s.indexOf('/') 2
val end = s.indexOf('.')
return s.substring(start, end)
}