RTF流字符替換

 

RTF流可能會有一些不需要的字符以及全角標點 會要替換掉。

下面代碼:

 

    /**
     * 
     * 處理全角標點符號和字體字符
     * 
     * @param hex
     * 
     *          源數據
     * 
     * @return
     * @see replaceQuanjiao
     */
    public static String replaceQuanjiao(String hex)
    {
      //需要替換爲空串的字符
        String regKey="(\\\\b0)|(\\\\b)|(\\\\f[0-9])|(\\\\cf[0-9][0-9] )|" +
                "(\\\\cf[0-9][0-9])|(\\\\cf[0-9])|(\\\\fs[0-9][0-9] )|(\\\\fs[0-9][0-9])|(\\\\fs[0-9])" +
                "|(\\\\hightlight[0-9])|(\\\\ulnone)|(\\\\ul)|(\\\\i0)|(\\\\i)|(\\r\\n)|(\\ltrpar)|(\\lang2052)";   
               
        Matcher matcher = Pattern.compile(regKey).matcher(hex);   
        hex = matcher.replaceAll("");
        /**
         * 這邊是需要替換的全角標點符號字符
         * 這個全角標點替換 貌似是有問題的
         */
        hex = hex.replace("\\ldblquote", "“").replace("\\rdblquote", "”").replace("\\lquote", "‘").replace("\\rquote", "’")
                .replace("\\emdash", "-").replace("\\line", "\r\n").replace("\\par", "\r\n").replace("\\tab", "  ").replace("\\{", "{")
                .replace("\\}", "}");
        return hex;
    }

 

http://www.cnblogs.com/liangqihui/articles/459154.html 這個帖子中描述了一下rtf流中的字符的意義 供參考.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章