开发者

How to NSLog with \n\r\t

开发者 https://www.devze.com 2023-01-05 18:05 出处:网络
In my application I am reading an HTML page to a string. HTML Page contains many tags, new lines & many other characters.

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? The reason behind this - I want to replace above style dynamically - but for replacing above I must have source to replac开发者_如何学Pythone - How to get source including \n&\r characters ?


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

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

精彩评论

暂无评论...
验证码 换一张
取 消