How to parse a string for newline characters and backslash in iPhone app?

I am making an app where there is a requirement to store ASCII art into database.

I store them in the below format in my Sqlite database.

"______\n |---------|-O\n/______\\n|________|\n\________/"

I want that when i retrieve them and display it in a label the newline characters and backslash should be parsed so as to display the real shape of the ASCII art into a label.

How should I parse this kind of strings?

I am a newbie soany examples or tutorials would be great help.

Please Help and Suggest.



NSString has a method to do what you want, which is to replace a litteral \n, with a newline character (which is symbolized as \n). In a c-format string you can use a double slash to let the library know the second slach is a real one and not an escape symbol. So this should work assuming you have been able to load your data from sqlite into an NSString:

newString = [yourStringFromSQLite stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];

try to use the scanner for remove the html entities

- (NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim {         
    NSScanner *theScanner;
    NSString *text = nil;
    theScanner = [NSScanner scannerWithString:html];
    while ([theScanner isAtEnd] == NO) {
        [theScanner scanUpToString:@"<" intoString:NULL] ;                 
        [theScanner scanUpToString:@">" intoString:&text] ;
        html = [html stringByReplacingOccurrencesOfString:[ NSString stringWithFormat:@"%@>", text] withString:@" "];
    return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;

and call this method where your trimmed string need to display

If you are using \n just for creating new lines then instead of that just keep space while inserting value in database and set following properties for label -> 1)keep width just to fit first word. 2)linebreakmode to wordwrap (so as width will not be available it will wrap next word to new line) 3)set no. of lines to 0 Hope this will help.

Need Your Help

Using ? (optionals) in Swift variables

ios swift optional-values

What exactly is the difference between a property definition in Swift of:

Solr suggester in SolrCloud mode

solr lucene solr4j

I am running the solr in CloudSolr mode with three shards. The data is already indexed into solr. Now I have configured the solr suggester in solrconfig.xml. This is the configuration from solrconfig

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.