I need to parse this string into three different components:
Location: 1|#69.83623|#24.432223|#Cupertino, California
The value is stored in one NSString. I need it in three different strings. One string for latitude, one for longitude and one for location.
Any idea how I can do that?
Thanks!
String Parsing "Parsing" is the process of taking a string from a file or the network or the user, and processing it to extract the information we want. A common strategy is to use a few calls to indexOf() to figure out the index numbers of something interesting inside the string.
Secondly, in Swift String is a struct, while in Objective-C, NSString is a class and inherit from NSObject . In concept, Swift String is more likely immutable. If we use a struct type and constant (remember the let keyword), we can keep out a lot of consideration of multi-thread programming and make us a better life.
String parsing is the process of dividing the string into tokens using delimiters to extract the desired information. This tutorial is about How to parse a string in python. We will learn how to parse the data strings into a list to extract our desired information using different methods and functions.
You can use this method to get an array of different components:
NSArray *bits = [locationString componentsSeparatedByString: @"|#"];
Each item in the NSArray will be an NSString.
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