RosettaCodeData/Task/Strip-comments-from-a-string/XPL0/strip-comments-from-a-string.xpl0
2023-07-01 13:44:08 -04:00

26 lines
643 B
Text

string 0; \use zero-terminated strings
func StripComment(Str); \Remove characters after marker and remove
char Str; int I; \ whitespace at beginning and end of string
[I:= 0;
loop case Str(I) of
^#, ^;, 0: quit
other I:= I+1;
while I>0 and Str(I-1)<=$20 do I:= I-1;
Str(I):= 0;
while Str(0)<=$20 do Str:= Str+1;
return Str;
];
int Strings, I;
[Strings:= [
" apples, pears # and bananas",
" apples, pears ; and bananas ",
" apples, pears "];
for I:= 0 to 3-1 do
[ChOut(0, ^");
Text(0, StripComment(Strings(I)));
ChOut(0, ^");
CrLf(0);
];
]