I'm developing a travel app, I have to read a txt file that contains all the states and countries, as you can notice this is a pretty huge file to read, anyway, this is an example of the text inside the file:
Zakinthos (ZTH),GREECE
Zanesville (ZZV),USA
Zanjan (JWN),IRAN
Zanzibar (ZNZ),TANZANIA
...
Now i'm reading the file with no problem but I don't know how to create two arrays, one with the state and another with the country so I can show them into a table when text is being autocompleted.
I've tried using NSScanner using the "," as a delimiter but I don't know how to make that works and also I tried with NSString methods with no results.
Any help is welcomed, Thank you in advance!!!.
btw sorry about my english XD
As the name suggests, a Java String Split() method is used to decompose or split the invoking Java String into parts and return the Array. Each part or item of an Array is delimited by the delimiters(“”, “ ”, \\) or regular expression that we have passed. The return type of Split is an Array of type Strings.
The split( ) method doesn't work directly for arrays. However, we can first convert the elements of our array to a string, then we can use the split( ) method.
The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.
The split() method splits (divides) a string into two or more substrings depending on a splitter (or divider). The splitter can be a single character, another string, or a regular expression. After splitting the string into multiple substrings, the split() method puts them in an array and returns it.
The easiest way to split a NSString into an NSArray is the following:
NSString *string = @"Zakinthos (ZTH),GREECE"; NSArray *stringArray = [string componentsSeparatedByString: @","];
This should work for you. Have you tried this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With