How to split a string


#1

Hi ,
Suppose string values is “ab_db_ef_gh_ij”. I want to split this string in terms of “_” and obtain a StringArray consisting of ad,df,ef,gh . Is there any inbuilt method in JUCE to split a sting


#2

i use that a lot so i’ll be writing from memory

StrigArray tokens;
tokens.addTokens (myString, "_", "\"");

for (int i=0; i<tokens.size(); i++)
{
   tokens[i]; // holds next token
}

(changed according to jules hints below)


#3

Thanks atom, but please avoid the T() macro in string literals now! Just

is shorter, neater, and (now that strings use UTF8 internally), faster!


#4

damn i need to change hundreds lines of code :slight_smile: thank god for find and replace.


#5

There’s no need to change your old stuff, it’ll still work fine - just avoid it in new code!


#6

Thanks to both of you . Its being real helpful reply