Tuesday, 20 May 2014

Replace specific string from a long text or line in iOS

 NSString *stringFromChange = [NSString stringWithFormat:@"hi this is pankaj"]];

stringFromChange = [stringFromChange stringByReplacingOccurrencesOfString:@"hi"


// Now output : hello this is pankaj

HTML content in UIWebView

NSString *body =@"<html><head><title>The Meaning of Life</title></head><body><p>...really is <b>42</b>!</p></body></html>  <p style='color:red' text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\"> <b> pankaj </b> <i>bhardwaj</i>  <u>test</u><img src='images_pv_tablet/4.png' width='202' height='152'>";
    NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
                                   "<head> \n"
                                   "<style type=\"text/css\"> \n"
                                   "body {font-family: \"%@\"; font-size: %@;}\n"
                                   "</style> \n"
                                   "</head> \n"
                                   "<body>%@</body> \n"
                                   "</html>", @"CronosPro-Regular", [NSNumber numberWithInt:fontVal], urString];

*/ // to set font


    NSData* data=[body dataUsingEncoding:NSUTF8StringEncoding];
    [NSURL URLWithString:@"nil"];
    if (data)
        [urWebView loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"nil"]];

    urWebView.dataDetectorTypes = UIDataDetectorTypeAll;