代码之家  ›  专栏  ›  技术社区  ›  sagarkothari

如何使用nslog \n\r\t

  •  0
  • sagarkothari  · 技术社区  · 15 年前

    在我的应用程序中,我正在将HTML页读取为字符串。HTML页面包含许多标记、新行和许多其他字符。

    <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>
    

    我想像下面那样替换这个字符串。 当我们在HTML页面上nslog时,它将按上面的样子打印。但我想记录的是

    \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>
    

    我的意思是包括反斜杠字符。有可能吗?这背后的原因-我想动态替换上面的样式-但要替换上面的样式,我必须有要替换的源-如何获取包含\n&\r字符的源?

    1 回复  |  直到 8 年前
        1
  •  4
  •   JeremyP    15 年前

    看看 NSString reference . 你需要这样的东西:

    string = [oldString stringByReplacingOccurrencesofString: @"\n" withString: @"\\n"];
    // repeat for \t  and \r
    
    推荐文章