Hello. I am coming from JS world and want to ask t...
# getting-started
j
Hello. I am coming from JS world and want to ask two things: 1. how to replace / from start string? i have path /path/something and want to remove first slash. Tried with
path.replace("/^\\/|\\/\$/g".toRegex(), "")
does not work. 2. what is easiest way to get search params as key value pair. /path/something?boom=true&id=bam. Want to have search params like boom:true , id: bam?
l
For the first question, you can use
path.trimStart('/')
, which will remove all slashes at the start of the string.
e
or
path.removePrefix("/")
to remove just one. the problem with your code is that you are including the
/
delimiters. you would have the same issue if you wrote
RegExp("/^\\/|\\/\$/g")
in JS too.
for 2, it depends; what environment are you in? in Kotlin/JS you can use the same
URLSearchParams
class that exists in JS. on Kotlin/JVM there's a few options
j
need it in android project
f
for Android, you are probably better off converting this to a Uri and then using the parse tools provided by that class. See this https://developer.android.com/reference/android/net/Uri
j
thx guys fixed it.