String split at
Remove a specific set of characters in a string at a specific point.
We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Sometimes you need to remove a set of characters in a string at a specific point. For example you might need to get access to the folder name of a directory.
iex> String.split_at("dev_folder/videos/thumbnail_01.png", 10)
# {"dev_folder", "/videos/thumbnail_01.png"}
The 10
is an argument and it means to split the string at 10
characters from the left.
You can use negative numbers to start at the end of the string. For example if you need to remove .png
extension on a path.
> String.split_at("dev_folder/videos/thumbnail_01.png", -4)
# {"dev_folder/videos/thumbnail_01", ".png"}
You could also use regular expression to filter these strings out as well.
Or you can try, using String.split/2
and pattern matching as I described in a blog post.