0

I want to set UIWebView with htmlstring and I have problem with an image: ...

<img align="absBottom" alt="" height="350" src="http://www.xyz.com//files/userfiles/images/abc.jpg" vspace="10" width="625" />

...

I want to replace height and width to 200 and 320. I'm using

htmlString = [htmlString stringByReplacingOccurrencesOfString:@"width=\"" withString:@"width=\"320]; 

then I've got result :

<img align="absBottom" alt="" height="350" src="http://www.xyz.com//files/userfiles/images/abc.jpg" vspace="10" width="320625" />

How to delete the number after the width from htmlString or what is the right way to replace the width to 320px?

makvalti
  • 87
  • 1
  • 9

2 Answers2

1

Try this using NSScanner:

NSScanner *theScanner;
NSString *subStrng =nil;
theScanner = [NSScanner scannerWithString:htmlString];
[theScanner scanUpToString:@"width" intoString:NULL] ;
[theScanner scanUpToString:@" " intoString:&subStrng] ;
htmlString = [htmlString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@", subStrng] withString::@"width=\"320\""];
NSLog("%@",subStrng);
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
Xcoder
  • 1,762
  • 13
  • 17
  • It works. Thank you. But changes only the first image in html code. – makvalti Oct 03 '13 at 12:05
  • 1
    Follow the link - http://stackoverflow.com/questions/6825834/objective-c-how-to-extract-part-of-a-string-e-g-start-with You'l need little modification. – Xcoder Oct 03 '13 at 12:18
0

Try this:

htmlString = [htmlString stringByReplacingOccurrencesOfString:@"width=\"625" withString:@"width=\"320];
Guy Kogus
  • 7,251
  • 1
  • 27
  • 32