Tokenize a string: Difference between revisions
Content added Content deleted
m (Fixed output D entry) |
No edit summary |
||
Line 1,666: | Line 1,666: | ||
MsgBox outP |
MsgBox outP |
||
End Sub</lang> |
End Sub</lang> |
||
=={{header|XPL0}}== |
|||
<lang XPL0>string 0; |
|||
include c:\cxpl\codes; |
|||
int I, J, K, Char; |
|||
char String, Array(5,6); \5 words and 5 maximum chars + terminating 0 |
|||
[String:= "Hello,How,Are,You,Today"; |
|||
I:= 0; K:= 0; |
|||
repeat J:= 0; |
|||
loop [Char:= String(I); |
|||
I:= I+1; |
|||
if Char=^, or Char=0 then quit; |
|||
Array(K,J):= Char; |
|||
J:= J+1; |
|||
]; |
|||
Array(K,J):= 0; \terminate word |
|||
K:= K+1; \next word in array |
|||
until K>=5; |
|||
for K:= 4 downto 0 do [Text(0, addr Array(K,0)); ChOut(0, ^.)]; |
|||
CrLf(0); |
|||
]</lang> |
|||
The 'addr' operator is used to fetch the 32-bit address of Array rather |
|||
than a byte from the character array. |
|||
Output (done in reverse order to emphasize the tokens are indeed separate): |
|||
<pre> |
|||
Today.You.Are.How.Hello. |
|||
</pre> |
|||
=={{header|Zsh}}== |
=={{header|Zsh}}== |