Stream: beginners

Topic: SubString


view this post on Zulip Gál Tamás (Dec 11 2023 at 07:58):

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.

view this post on Zulip Luke Boswell (Dec 11 2023 at 08:28):

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

view this post on Zulip Luke Boswell (Dec 11 2023 at 08:31):

I also use Str.split pretty frequently

view this post on Zulip Gál Tamás (Dec 11 2023 at 08:36):

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.

view this post on Zulip Gál Tamás (Dec 11 2023 at 08:51):

For a unicode text maybe it can be solved with the Str.walkUtf8WithIndex to get out from the given position

view this post on Zulip Isaac Van Doren (Dec 11 2023 at 15:03):

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