I am quote new in Roc and probably it is a silly question but I was reading the tutorial and I have not found a substring/slice solution in the Str module. How can I get out a substring from a string? Thanks.
The reason it isn't in the builtins is because working with unicode strings can be complicated. The plan is for text segmentation to be provided by a library that is currently a WIP over at roc-lang/unicode. Is there a particular use case or thing you were trying to do? There may be another way to achieve what you need
I also use Str.split pretty frequently
Thanks. I see. I was just thinking of different string manipulations like in other languages to process a given string, Sometimes I don't have a special character to use in split. Eg. I store some information in a string in a specific position and I need to get it out. It is ansii text , not unicode.
For a unicode text maybe it can be solved with the Str.walkUtf8WithIndex to get out from the given position
You can also do Str.toUtf8 followed by List.sublist if your use case allows it
Last updated: Jul 05 2025 at 12:14 UTC