Hi all :slightly_smiling_face: How can i use `remo...
# getting-started
l
Hi all 🙂 How can i use
removePrefix()
if i have this string
Expiration Date: "2023-01-03 16:06:52 +0000 UTC"
and i want to get
"2023-01-03 16:06:52 +0000 UTC"
Copy code
.removePrefix("Expiration Date: ")
i tried this but seems like not working as expected
c
Are you looking at the original string or the result of removePrefix?
j
This function returns a new modified string, it doesn't mutate the original
👍 1
l
@corneil i am looking at the original string
c
String is immutable. Thus no method modifies a String directly. The methods returns a new String that is modified accordingly.
l
cool 🙂 succeeded with
drop(n)
j
But why use
drop
instead of
removePrefix
?
ö
You can also use
substringAfter
👍 1
l
@Joffrey i tried to use
removePrefix
but it didnt work
j
Are you sure you have the correct case for the prefix? Maybe the
D
is lowercase in the actual input?
This definitely works:
Copy code
val input = "Expiration Date: \"2023-01-03 16:06:52 +0000 UTC\""
val output = input.removePrefix("Expiration Date: ")
println(output) // prints "2023-01-03 16:06:52 +0000 UTC"
https://pl.kotl.in/JKslLmEkY
👀 1