Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString parsing

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!

like image 776
Magnus Avatar asked Jan 03 '12 13:01

Magnus


People also ask

What is string parsing?

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.

What is the difference between NSString and 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.

What is string parsing in Python?

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.


1 Answers

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.

like image 105
Thomas Clayson Avatar answered Oct 29 '22 02:10

Thomas Clayson