Split a character string based on change of character: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (REXX Version 2 - add REXX header) |
(Brought the three BASIC dialects under BASIC heading) |
||
Line 229: | Line 229: | ||
</pre> |
</pre> |
||
=={{header| |
=={{header|BASIC}}== |
||
===BaCon=== |
|||
Literal strings in BaCon are passed to the C compiler as they are; a backslash therefore needs to be escaped. |
Literal strings in BaCon are passed to the C compiler as they are; a backslash therefore needs to be escaped. |
||
<lang freebasic>txt$ = "gHHH5YY++///\\" |
<lang freebasic>txt$ = "gHHH5YY++///\\" |
||
Line 248: | Line 249: | ||
</pre> |
</pre> |
||
== |
===BBC BASIC=== |
||
<lang bbcbasic>REM >split |
<lang bbcbasic>REM >split |
||
PRINT FN_split( "gHHH5YY++///\" ) |
PRINT FN_split( "gHHH5YY++///\" ) |
||
Line 268: | Line 269: | ||
{{out}} |
{{out}} |
||
<pre>g, HHH, 5, YY, ++, ///, \</pre> |
<pre>g, HHH, 5, YY, ++, ///, \</pre> |
||
===tbas=== |
|||
{{Trans|BBC BASIC}} |
|||
<lang basic>SUB SPLITUNIQUE$(s$) |
|||
DIM c$, d$, split$, i% |
|||
c$ = LEFT$(s$, 1) |
|||
split$ = "" |
|||
FOR i% = 1 TO LEN(s$) |
|||
d$ = MID$(s$, i%, 1) |
|||
IF d$ <> c$ THEN |
|||
split$ = split$ + ", " |
|||
c$ = d$ |
|||
END IF |
|||
split$ = split$ + d$ |
|||
NEXT |
|||
RETURN split$ |
|||
END SUB |
|||
PRINT SPLITUNIQUE$("gHHH5YY++///\") |
|||
END</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |