views:

112

answers:

1

Hello ! Every one.

In my application I am reading an HTML page to a string. HTML Page contains many tags, new lines & many other characters.

<style type="text/css">
    h3{ 
        font-weight:bold;
        line-height:18px;
        font-family:Arial;
        font-size:12px; 
        text-align:justify; 
        color:black; 
        background-color:transparent;
        width:280px;
        margin:0;
    }

    body{ 
        font-weight:normal;
        line-height:18px;
        font-family:Arial;
        font-size:12px; 
        text-align:justify; 
        color:black; 
        background-color:transparent;
        width:280px;
    }
</style>

I want to replace this string like following. When we NSLog above HTML page, it will print as above looks. But What I want to NSLog is as follows

\t\t<style type="text/css">\n\t\t\th3{\n
        font-weight:bold;
        line-height:18px;
        font-family:Arial;
        font-size:12px; 
        text-align:justify; 
        color:black; 
        background-color:transparent;
        width:280px;
        margin:0;
    }

    body{ 
        font-weight:normal;
        line-height:18px;
        font-family:Arial;
        font-size:12px; 
        text-align:justify; 
        color:black; 
        background-color:transparent;
        width:280px;
    }
</style>

I mean including backslash characters. Is it possible ? How ? The reason behind this - I want to replace above style dynamically - but for replacing above I must have source to replace - How to get source including \n&\r characters ?

Thanks in advance for sharing your knowledge. Please add comment if needed.

Sagar.

+2  A: 

Look at the NSString reference. You'll need something like:

string = [oldString stringByReplacingOccurrencesofString: @"\n" withString: @"\\n"];
// repeat for \t  and \r
JeremyP