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"}
Other ways
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.