Strings

String variables are variables with a name starting with S or gS (for a local or global string variable, respectively), and can store any string with a maximum length defined by the -+max_str_len command line flag (255 characters by default). These variables can be used as input argument to any opcode that exepcts a quoted string constant, and can be manipulated at initialization or performance time with the opcodes listed below.

It is also possible to use string p-fields. The string p-field can be used by many orchestra opcodes directly, or it can be copied to a string variable first:

a1    diskin2 p5, 1
    

Sname strget p5
a1    diskin2 Sname, 1
    

[Note] Note
String variables and related opcodes are not available in Csound versions older than 5.00.

Strings can also be linked to a number using strset and strget.

String Conversion Opcodes

Csound 5 also has improvements in parsing string constants. It is possible to specify a multi-line string by enclosing it within {{ and }} instead of the usual double quote characters (note that the length of string constants is not limited, and is not affected by the -+max_str_len option), and the following escape sequences are automatically converted:

  • \a alert bell

  • \b backspace

  • \n new line

  • \r carriage return

  • \t tab

  • \\ a single '\' character

  • \nnn the character of which the ASCII code (in octal) is nnn

These opcodes perform operations on string variables (note: most of the opcodes run at init time only, and have a version with a "k" suffix that runs at both init and performance time; exceptions to this rule include puts and strget):

  • strcpy - Assigns to a string variable.
  • strcat - Concatenates strings, and stores the result in a variable.
  • strcmp - Compares strings.
  • strget - Assigns to a string variable, from strset table at the specified index, or string score p-field.
  • strlen - Returns the length of a string.
  • sprintf - printf-style formatted output conversion, storing the result in a string variable.
  • puts - Prints a string constant or variable.
  • strtod - Converts string value to a floating point value at i-rate.
  • strtol - Converts string value to signed integer at i-rate.
  • strchar - Returns the ASCII code of a character in a string.
  • strsub - Returns a substring of the input string.
  • strlower - Converts a string to lower case.
  • strupper - Converts a string to upper case.
  • strindex - Returns the first occurence of a string in another string.
  • strrindex - Returns the last occurence of a string in another string.