当前位置: 首页>>代码示例>>C#>>正文


C# StringBuffer.CharAt方法代码示例

本文整理汇总了C#中StringBuffer.CharAt方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuffer.CharAt方法的具体用法?C# StringBuffer.CharAt怎么用?C# StringBuffer.CharAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringBuffer的用法示例。


在下文中一共展示了StringBuffer.CharAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: saveConvert

        /*
           * Converts unicodes to encoded \uxxxx and writes out any of the
           * characters in specialSaveChars with a preceding slash
           *
           * @param theString
           *            the string needing convert.
           * @param dst
           *            Save of the result
           * @param offset
           *            the offset of result
           * @param escapeSpace
           *            if <code>true</code>, escape Space
           * @param lengthFlag
           *            Whether add one byte of length in the result.
           *            <code>true</code> add one byte of length in the result
           * @param getLengthFlag
           *            Calculate the length of result, if <code>true</code>, thestring length that return.
           * @return  if getLengthFlag = false, return offset of the result.
           *          if getLengthFlag = true, the length of the sequence of characters represented by this
           *          object.
           */
        public static int saveConvert(string theString, byte[] dst, int offset, bool escapeSpace, bool lengthFlag, bool getLengthFlag)
        {
            if (false == getLengthFlag
                && (null == dst || dst.Length < (offset + (lengthFlag ? 1 : 0))
                || dst.Length < 1 || offset < 0))
                return -1;
            if (null == theString)
                theString = "";
            int length = theString.Length;

            StringBuffer outBuffer = new StringBuffer (length * 2);

            for (int x = 0; x < length; x++) {
                char aChar = theString [x];
                switch (aChar) {
                case ' ':
                    if (x == 0 || escapeSpace)
                        outBuffer.Append ('\\');

                    outBuffer.Append (' ');
                    break;
                case '\\':
                    outBuffer.Append ('\\');
                    break;
                case '\t':
                    outBuffer.Append ('\\');
                    outBuffer.Append ('t');
                    break;
                case '\n':
                    outBuffer.Append ('\\');
                    outBuffer.Append ('n');
                    break;
                case '\r':
                    outBuffer.Append ('\\');
                    outBuffer.Append ('r');
                    break;
                case '\f':
                    outBuffer.Append ('\\');
                    outBuffer.Append ('f');
                    break;
                default:
                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
                        outBuffer.Append ('\\');
                        outBuffer.Append ('u');
                        outBuffer.Append (toHexChar ((aChar >> 12) & 0xF));
                        outBuffer.Append (toHexChar ((aChar >> 8) & 0xF));
                        outBuffer.Append (toHexChar ((aChar >> 4) & 0xF));
                        outBuffer.Append (toHexChar (aChar & 0xF));
                    } else {
                        if (specialSaveChars.IndexOf (aChar) != -1)
                            outBuffer.Append ('\\');
                        outBuffer.Append (aChar);
                    }
                    break;
                }
            }
            length = outBuffer.Length ();
            if (length > 255)
                length = 255;
            if (!getLengthFlag) {
                if (dst.Length >= offset + length + (lengthFlag ? 1 : 0)) {
                    if (lengthFlag) {
                        dst [offset] = (byte)(length & 0xFF);
                        offset++;
                    }
                    for (int i = 0; i < length; i++) {
                        dst [offset] = (byte)outBuffer.CharAt (i);
                        offset++;
                    }
                    length = offset;
                } else {
                    length = -1;
                }
            } else {
                if (lengthFlag)
                    length = length + 1;
            }

            outBuffer = null;
//.........这里部分代码省略.........
开发者ID:Coopermine,项目名称:P25M_PRINTER,代码行数:101,代码来源:StringUtil.cs


注:本文中的StringBuffer.CharAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。