ios - NSString characterSetWithCharactersInString returns empty strings -
i'm trying break nsstring
comma separated components. somehow nsstring
containing 25000 components returns 25.500 values, 500 of empty nsstrings
. here's code looks like:
nsstring* filecontents = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:nil]; /* stuff */ nsmutablearray* components = [nsmutablearray arraywitharray: [filecontents componentsseparatedbycharactersinset: [nscharacterset charactersetwithcharactersinstring:@",\n\r "]]];
consider example:
[@"\n,\n"componentsseparatedbycharactersinset: [nscharacterset charactersetwithcharactersinstring:@",\n\r "]];
the result shows how componentsseparatedbycharactersinset:
behaves. 4 components, empty strings. see why?
i'm not quite sure expecting do, do. splits @ of characters list. if 2 of them next each other, empty string. plus string before first 1 , string after last one.
so reason getting 25500 components that, given command gave, how many components there are.
Comments
Post a Comment