Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I use:
Code:
NSURL *url = [NSURL URLWithString:@"http://www.myservername.org/file.html"];
    self.content = [NSString stringWithContentsOfURL:url];
This returns all of the text, and pretty much everything in it. If the user has stored their name in the app, it scans the text in self.content for a match. If it has a match, it gives the user a message in a uialertview. I would like to provide more details about why their name is in the document, but am unsure about how to do this. As I control the document, I can format it any way I like. I was thinking about having only 1 name per line, and having the alertview show the entire line. How could I go about scanning for a match with the NSUserDefaults for their name, and return everything else on that same line between the line breaks?
 

cMacSW

macrumors regular
Mar 20, 2006
180
0
Not exactly sure from your description, but I'd approach it this way:

Use NString's componentsSeparatedByString method and pass @"\n" for the separator. This will give you an array with one line of text in each element of the array.

Than I'd use NSArray's filteredArrayUsingPredicate method to determine if any lines contain the name.

This would be good for searching for multiple items, but maybe not efficient if your looking for just 1 name once. If that's the case I'd search the string directly and extract the data directly.
 

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
Not exactly sure from your description, but I'd approach it this way:

Use NString's componentsSeparatedByString method and pass @"\n" for the separator. This will give you an array with one line of text in each element of the array.

Than I'd use NSArray's filteredArrayUsingPredicate method to determine if any lines contain the name.

This would be good for searching for multiple items, but maybe not efficient if your looking for just 1 name once. If that's the case I'd search the string directly and extract the data directly.

There are some instances in which the name could be entered in multiple times. It is basically just a schedule html file, and I currently have it string the contents. If it finds a match with the NSUserDefault for their name, it pops up the alert view stating they have been scheduled for something, and need to check the schedule to see what. I would like to be able to eliminate that last step, and have the alertview pull from the string, telling them exactly what they are doing. Just not sure how to extract that. I do get what you were saying at the beginning, just not the last part of "If that's the case..."

Edit, and I know that stringContentsofUrl is deprecated, so in future versions not sure of how to do even the current part I am doing.
 
Last edited:

cMacSW

macrumors regular
Mar 20, 2006
180
0
Can you provide an example of the data maybe a line or two and the field you're seating for and the field you'd like to extract.
 

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
Can you provide an example of the data maybe a line or two and the field you're seating for and the field you'd like to extract.

The html is http://www.bellavenue.org/worship.html

Each line has an area of worship, and the person assigned to that area. I'd like to search for a name, and then what line it is on, and present an UIAlertView that combines both lines to tell the user exactly what they are scheduled for.
 

cMacSW

macrumors regular
Mar 20, 2006
180
0
So here's a random line from your sample data:

<p class="p1"><span class="s1">Welcome</span>: Tyler Brassfield</p>

Assuming you use NSStrings componentsSeparatedByString then each component would be like the line above. you could then use the same method to break this down into the following components
<p class="p1">
<span class="s1">
Welcome</span>
: Tyler Brassfield</p>

then you can use substring methods to trim the strings.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.