up previous next

OpenIString, OpenOString

Syntax

OpenIString(S:STRING,T:STRING):DEVICE
OpenOString(S:STRING):DEVICE
    

Summary

open input or output string

Description

These functions open strings for input or output. The string S serves as the name of the device opened for input or output; one may use the empty string. OpenIString is used to read input from the string T with the help of Get. OpenOString is used to write to a string with the help of Print On.

example

    
S := "hello world";
D := OpenIString("",S);  -- open the string S for input to CoCoA
L:= Get(D,7);  -- read 7 characters from the string
L;  -- ascii code
[104, 101, 108, 108, 111, 32, 119]
-------------------------------
Ascii(L); -- convert ascii code to characters
hello w
-------------------------------
Close(D);  -- close device D
D := OpenOString("");  -- open a string for output from CoCoA
L := [1,2,3]; -- a list
Print L On D;  -- print to D
D;
Record[Name = "", Type = "OString", Protocol = "CoCoAL"]
-------------------------------
S := Cast(D,STRING);  -- S is the string output to D
S; -- a string
[1, 2, 3]
Print " more characters" On D;  -- append to the existing output string
Cast(D,STRING);
[1, 2, 3] more characters
-------------------------------
        
    

See Also