2

I am getting following html string in webservice response :-

NSString *str=@"<div class="ProductDescription"><h3><span style="font-size: large;">kjdhfdsghfjsdjgf</span></h3></div>";

[webview loadHTMLString:str baseURL:nil];

I am using following code for getting length of html string

-(void)webViewDidFinishLoad:(UIWebView *)webView
{

    int height=[webView stringByEvaluatingJavaScriptFromString: @"document.getElementByClass(\"ProductDescription\").offsetHeight;"];

}

How could I get the length of above HTML string in webViewDidFinishLoad so that I can set dynamic height for webview?

Rahul gupta
  • 129
  • 8
  • That's a local string not a string from a webservice response? Are you loading that string in yourself? – Popeye Oct 14 '14 at 13:07
  • Please don't un-edit correctly formatted code. – Popeye Oct 14 '14 at 13:16
  • It's unclear what's being asked for here. You ask for the "length" of the string, but then you also mention that you want to set a "height", which makes me think that you don't want the length of the string, but to either know how many vertical screen points it'll take up when the string is rendered in plain text, or how many vertical screen points it'll take up when the string is rendered as an HTML page. – ArtOfWarfare Oct 14 '14 at 17:15
  • Did you found any solution?? – Tarun Seera Apr 12 '16 at 11:11

2 Answers2

0

if by "html string" you refer to the first line so it is [str length]

TheLongOne
  • 39
  • 1
  • 4
  • The question is unclear, but I don't think this is what the asker was looking for. Even so, I'm marking this as "Looks OK" in response to a flag someone else raised for this. If anything should be flagged, it's the question for not being clear enough (and in fact, I'm going to raise a flag on it now.) – ArtOfWarfare Oct 14 '14 at 17:12
0

Maybe you have to trim spaces in html string for true results. String replacement in Objective-C

After use [str length] like above.

Community
  • 1
  • 1
Gokhan Gultekin
  • 291
  • 5
  • 15