zoukankan      html  css  js  c++  java
  • 转义字符 显示形式 转换成 实际形式 \\n to \n

    类1

    public class EscapeCharacterEntities
    {
        private static object _lookupLocker = new object();
        private static string[] _entitiesList = new string[]
        {
            "\n-n"
            "\r-r",
            "\t-t"
            "\f-f",           
            "\v-v" 
        };
        private static Hashtable _entitiesLoopupTable;
        private EscapeCharacterEntities() { }
        public static char Lookup(string entity)
        {
            if (_entitiesLoopupTable == null)
            {
                lock (_lookupLocker)
                {
                    if (_entitiesLoopupTable == null)
                    {
                        Hashtable curTable = new Hashtable();
                        foreach (string item in _entitiesList)
                        {
                            curTable[item.Substring(2)] = item[0];
                        }
                        _entitiesLoopupTable = curTable;
                    }
                }
            }
            object obj = _entitiesLoopupTable[entity];

            return obj == null ? (char)0 : (char)obj;
        }
    }

    转换方法

    public static string EscapeCharacterFormat(string input)
    {
        StringBuilder builder = new StringBuilder();
        StringWriter writer = new StringWriter(builder);
        int l = input.Length;
        int maxIndex = l - 1;
        for (int i = 0; i < l; i++)
        {
            char ch = input[i];
            if (ch == '\\' && i < maxIndex)
            {
                char ch2 = input[i + 1];
                char curchar = EscapeCharacterEntities.Lookup(ch2.ToString());
                if (curchar != (char)0)
                {
                    writer.Write(curchar);
                    i++;
                    continue;
                }
            }
            writer.Write(ch);
        }
        return builder.ToString();
    }
  • 相关阅读:
    centos7安装jdk8
    centos7安装mysql5.7.31
    docker打包,运行springboot
    centos7安装docker
    ps学习记录
    Html的学习(二)
    tensorflow C++接口调用图像分类pb模型代码
    tensorflow C++接口调用目标检测pb模型代码
    ubuntu14 编译tensorflow C++ 接口
    Python opencv计算批量图片的BGR各自的均值
  • 原文地址:https://www.cnblogs.com/yelaiju/p/2727237.html
Copyright © 2011-2022 走看看