Manipulate Comma-Text

Also called comma separated list it's an efficient way to define a list of names with a single string. Many modules in Usine have comma text inlets or outlets: listbox and combobox items, file lists, captions, and the comma-text modules listed below.

For example "item 1","item 2","item 3" (or item 1,item 2,item 3) will set the file list to

  • item 1
  • item 2
  • item 3

Reading a comma-text

  • Items are separated by commas ,. Only the comma and the double quote " have a special meaning: the single quote ', the semicolon ; and line breaks are ordinary characters.
  • Spaces belong to the items: they are neither removed nor used as separators.
  • An item that starts with a double quote ends at the next double quote, and both quotes are removed: such an item can contain commas. Inside it, a double quote is written twice "".
  • A double quote that is not at the start of an item is an ordinary character.
  • Two consecutive commas, or a comma at the start or at the end of the text, give an empty item.
  • An empty string is a list of 0 items, "" is a list of 1 empty item.
  • Items are indexed from 0 and can contain any Unicode character.
comma text = 'red,green,blue'
items      = 'red' 'green' 'blue'
comma text = 'red, green'
items      = 'red' ' green'
comma text = '"Smith, John","say ""hi""",x'
items      = 'Smith, John' 'say "hi"' 'x'
comma text = '"red", "green"'
items      = 'red' ' "green"'
comma text = 'a,,b,'
items      = 'a' '' 'b' ''

Avoid double quotes inside items when the comma-text goes to other modules than the comma-text modules and the listboxes: inlets that read a list item by item (file names, textures, chunks...) don't decode "" and take any double quote as the start or the end of a quoted part.

Writing a comma-text

When a module outputs a comma-text, items are separated by commas without spaces. An item is written between double quotes only if it contains a comma or a double quote, its double quotes being then written twice. A list of 1 empty item is written "".

items      = 'Smith, John' 'say "hi"' 'x y' ''
comma text = '"Smith, John","say ""hi""",x y,'

See also

version 7.0.250921

Edit All Pages