How to split a string


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


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)


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

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


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


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


Thanks to both of you . Its being real helpful reply