RTF流字符替换

来源:互联网 发布:前端 后端 知乎 编辑:程序博客网 时间:2024/05/01 17:28

 

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流中的字符的意义 供参考.

 

原创粉丝点击