## 4.22 string

Variables of type `string` are used for output (almost every type can be "converted" to `string`) and for creating new commands at runtime see execute. They are also return values of certain interpreter related functions (see Functions). String constants consist of a sequence of ANY characters (including newline!) between a starting `"` and a closing `"`. There is also a string constant `newline`, which is the newline character. The `+` sign "adds" strings, `""` is the empty string (hence strings form a semigroup). Strings may be used to comment the output of a computation or to give it a nice format. Strings may also be used for intermediate conversion of one type into another.

      string s="Hi";
      string s1="a string with new line at the end"+newline;
      string s2="another string with new line at the end
      ";
      s;s1;s2;
    ==> Hi
    ==> a string with new line at the end
    ==>
    ==> another string with new line at the end
    ==>
      ring r; ideal i=std(ideal(x,y^3));
      "dimension of i =",dim(i),", multiplicity of i =",mult(i);
    ==> dimension of i = 1 , multiplicity of i = 3
      "dimension of i = "+string(dim(i))+", multiplicity of i = "+string(mult(i));
    ==> dimension of i = 1, multiplicity of i = 3
      "a"+"b","c";
    ==> ab c

A comma between two strings makes an expression list out of them (such a list is printed with a separating blank in between), while a `+` concatenates strings.

> 4.22.1 string declarations |  |
> 4.22.2 string expressions |  |
> 4.22.3 string type cast |  |
> 4.22.4 string operations |  |
> 4.22.5 string related functions |  |

User manual for Singular version 4.4.1, 2025, generated by texi2html.