Wednesday 15 June 2011

iphone - iOS - Convert part of an Array Element into a String -


So I loose for parsing HTML in a master / extension app.

I'm trying to change NSArray to an NSString, but only the only element (only one element) is not being completely parsed.

My code:

viewcontroller.h:

  #import & lt; UIKit / UIKit.h & gt; @ Interface viciViewController: UIViewController {IBOutlet UITextView * label; IBOutlet UITextField * TextField; IBOutlet UITextView * Translation; IBOutlet UIButton * transButton; BOOL connected internet; } - translate (IBAction) button; @end   

viewcontroller.m:

  #import "viciViewController.h" #import "TFHpple.h" @interface viciViewController () @end @implementation ViciViewController - (BOOL) connected connectioNet {NS URL * url = [NSURL URLWithString: @ "http://www.google.com"]; NSMutableURL request * request = [NSMutableURL request request withURL: url]; [Set http system: @ "head"]; NSHTTPURL response * feedback; [Synchronous request to send NSUr connection: Request to be reacting back: and response error: zero]; Return ([response statusCode] == 200)? Yes No; } - (IBAction) translateButton {if ([self-connected internet] == ​​no) {translation.text = @ "Sorry, you need an internet connection to translate."; // not connected to the Internet} and {// connected to the Internet [Textfield Residents First Responder]; NSString * toTranslate = self- & gt; Textfield.Text; NSString * url = [NSString stringWithFormat: @ "http://www.archives.nd.edu/cgi-bin/wordz.pl?keyword=%@", Troubleshoot]; Ns URL * translation URL URL = [NSURL URL with string:]; NSDT * Translation HTML Data = [NSDATA DATAVITY Content of URL: Translation URL]; TFHpple * Translation Parser = [TFHpple hppleWithHTMLData: translationHtmlData]; // 3 NSString * Translation XpathQueryString = @ "/ html / body / pre"; NSArray * translation = output = [translation reader searchwithexax: Translation XpathQueryString]; NSString * Result = [[translationApplication ManFor: @ "Details"] ComponentsZonedBusiness: @ ""]; NSLog (@ "response% @", result); }   

The log in the console says:

  feedback {nodeChildArray = ({nodeContent = "\ nsemper ADV POS \ nsemper ADV [XXXAX] \ nalways ; \ N \ n "; nodename = text;}); Nodename = east; Raw = "& lt; Pre & gt; Consolidation ADV POS \ nSemper ADV [XXXAX] \ nalways; \ n \ n   

So, question: Is it possible to get the bus node communication in the form of NSSTING and to turn on \ n in carriage return is?

Thanks for all help!

TFHppleElement does that:

Your code

  NSString * result = [[change the following lines in componentsJoinedByString: ["translation output value FORKEY: @" description "]: @" "]; NSLog (@ "response% @", result);   

with the following:

  NSString * translatedString = ((TFHppleElement *) translation output [0]). FirstChild.content; NSLog (@ "% @", translated string); Do not forget to include   

TFHppleElement.h


Output

If you send semper then the result stored in translatedString is

CMP ADV POS - CMPR ADV [XXXAX]
Always;

No comments:

Post a Comment