-
How can I split a string on a delimiter in Scryer Prolog? |
Beta Was this translation helpful? Give feedback.
Answered by
triska
Jul 24, 2023
Replies: 1 comment 8 replies
-
In Scryer Prolog, you can easily reason about strings as lists, so the predicates from For example: :- use_module(library(lists)). :- use_module(library(reif)). split("", _, []). split(String, Char, Segments0) :- if_(memberd_t(Char, String), ( Segments0 = [Segment|Segments], once(append(Segment, [Char|Rs], String)), split(Rs, Char, Segments) ), Segments0 = [String] ). Yielding: ?- split("hello.all.there", ., Rs). Rs = ["hello","all","there"]. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe
append/3
?