Tokenize a string: Difference between revisions
Content added Content deleted
({{omit from|PARI/GP}}) |
(Added Prolog version) |
||
Line 940: | Line 940: | ||
<lang powershell>$words = "Hello,How,Are,You,Today" -split ',' |
<lang powershell>$words = "Hello,How,Are,You,Today" -split ',' |
||
$words -join '.'</lang> |
$words -join '.'</lang> |
||
=={{header|Prolog}}== |
|||
{{works with|SWI Prolog}} |
|||
<lang prolog>splitup(Sep,[token(B)|BL]) --> splitup(Sep,B,BL). |
|||
splitup(Sep,[A|AL],B) --> [A], {\+ [A] = Sep }, splitup(Sep,AL,B). |
|||
splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL). |
|||
splitup(_Sep,[],[]) --> []. |
|||
start :- |
|||
phrase(splitup(",",Tokens),"Hello,How,Are,You,Today"), |
|||
phrase(splitup(".",Tokens),Backtogether), |
|||
string_to_list(ABack,Backtogether), |
|||
writeln(ABack).</lang> |
|||
Output: |
|||
<pre>?- start. |
|||
Hello.How.Are.You.Today</pre> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |