https://kotlinlang.org logo
#announcements
Title
# announcements
s

sqia09

09/27/2017, 9:10 AM
hey, how can I trim last 4 or 5 characters from string using collection functions?
d

diesieben07

09/27/2017, 9:14 AM
What exactly do you mean by "collection functions"? If you want to remove the last 4 characters of a String,
substring
is what you want:
Copy code
val s = "Hello World"
s.substring(0, s.length - 5)
m

marstran

09/27/2017, 9:15 AM
You can use `dropLast`:
"Hello World!".dropLast(5)
👍 3
g

gildor

09/27/2017, 9:22 AM
also maybe it’s a good question for #getting-started
s

sqia09

09/27/2017, 9:42 AM
thanks.
3 Views