StringArray - populate array from comma divided string


#1

hey jules,
ive been using this method alot, and i guess it might be helpfull to others if it were implemented in StringArray

addCommaSeparatedStrings(String stringsToAdd) { String singleString; while (stringsToAdd.isNotEmpty()) { singleString = stringsToAdd.upToFirstOccurrenceOf(T(","), false, false).trim(); if (singleString.isNotEmpty()) { add(singleString); } stringsToAdd= stringsToAdd.fromFirstOccurrenceOf(T(","),false, false); } }

or better yet:

addSeparatedStrings(String stringsToAdd, const tchar* const dividingChar) { String singleString; while (stringsToAdd.isNotEmpty()) { singleString = stringsToAdd.upToFirstOccurrenceOf(dividingChar, false, false).trim(); if (singleString.isNotEmpty()) { add(singleString); } stringsToAdd= stringsToAdd.fromFirstOccurrenceOf(dividingChar,false, false); } }


#2

int StringArray::addTokens (const tchar *const stringToTokenise, const tchar * breakCharacters, const tchar * quoteCharacters) throw ()
Breaks up a string into tokens and adds them to this array.

This will tokenise the given string (using the string passed in to define the token delimiters), and will add these tokens to the end of the array.

Parameters:
[list]
[]stringToTokenise the string to tokenise[/]
[]breakCharacters a string of characters, any of which will be considered to be a token delimiter.[/]
[]quoteCharacters if this string isn’t empty, it defines a set of characters which are treated as quotes. Any text occurring between quotes is not broken up into tokens.[/][/list]
Returns:
[list]
[]the number of tokens added[/][/list]

http://www.rawmaterialsoftware.com/juce/api/classStringArray.html#87fb7188e63ab95d50f2ae405ee8ae20


#3