up previous next
1.8.4 String IO
***** NOT YET UPDATED TO CoCoA-5: follow with care *****

To print CoCoA output to a string, on may use OpenOString to open the string, then print on to write to it. To read from a string, one may open the string for input with OpenIString then read substrings from it with GetLine .

Example
/**/  S := "hello world!\ngoodbye world!";
/**/  D := OpenIString(S);  -- open the string S for input to CoCoA
/**/  line := GetLine(D);  -- read 1st line from the string
/**/  line;
hello world!
/**/  Close(D);  -- close device D
There are usually more direct ways to collect results in strings. For instance, if the output of a CoCoA command is not already of type STRING , one may convert it to a string using sprint .