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


C# StringBuffer.Length方法代码示例

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


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

示例1: dump

        public static string dump(byte[] abyte0, int beginIndex, int endIndex, bool spaceFlag, bool asciiFlag, bool lineNumberFlag, int linenumber)
        {
            byte[] cont = abyte0;
            if(abyte0 == null || cont.Length  == 0)
                return "";

            string outMsg = "";
            int totalLine = (endIndex - beginIndex) / 16;
            int lineNumber, q;
            int offset = beginIndex;
            byte byte0;
            StringBuffer stringbuffer = new StringBuffer(6 + (spaceFlag?48:32));
            StringBuffer asciibuffer = new StringBuffer();
            string printString;
            int stringcount;
            int asccicount;

            if (linenumber < 0)
                linenumber = 0;
            else
                linenumber = linenumber % 10000;

            for(int i = 0; i <= totalLine; i++, linenumber++)
            {
                if (offset < endIndex) {
                    stringcount = stringbuffer.Length();
                    asccicount = asciibuffer.Length();
                    stringbuffer.Delete(0, stringcount);
                    asciibuffer.Delete(0, asccicount);
                    if (lineNumberFlag) {
                        stringbuffer.Append("0000: ");
                        lineNumber = linenumber;
                        for(byte0 = 3; byte0 >=0; byte0--){
                            q = (lineNumber * 52429) >> (16+3);
                            stringbuffer.SetCharAt(byte0, toHexChar(lineNumber - ((q << 3) + (q << 1)))); // toHexChar(lineNumber-(q*10))
                            lineNumber = q;
                            if (0 == lineNumber) break;
                        }
                    }
                    for(int j = 0; j < 16; j++, offset++)
                    {
                        if (offset < endIndex) {
                            byte0 = abyte0[offset];
                            stringbuffer.Append(toHexChar(byte0 >> 4));
                            stringbuffer.Append(toHexChar(byte0));
                            if (spaceFlag)
                                stringbuffer.Append(' ');
                            if (asciiFlag) {
                                if (byte0 >= 0x20 && byte0 <= 0x7E)
                                    asciibuffer.Append((char)byte0);
                                else
                                    asciibuffer.Append('.');
                            }
                        } else {
                            stringbuffer.Append(' ');
                            stringbuffer.Append(' ');
                            if (spaceFlag)
                                stringbuffer.Append(' ');
                        }
                    }
                    if (asciiFlag)
                        printString = stringbuffer.ToString() + "; " + asciibuffer.ToString();
                    else
                        printString = stringbuffer.ToString();
                    //        printLine(printString);
                    outMsg =  outMsg + printString + "\n";
                } else {
                    break;
                }
            }
            printString = null;
            stringbuffer = asciibuffer = null;
            return outMsg;
        }
开发者ID:Coopermine,项目名称:P25M_PRINTER,代码行数:74,代码来源:Tracer.cs

示例2: saveConvert

        /*
           * Converts unicodes to encoded &#92;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

示例3: seperateStr

        /**
         * Seperate String with str token
         *
         * @param str - the string which will be cut
         * @return cut string array
         */
        // @SuppressWarnings("unused")
        private static string[] seperateStr(string str)
        {
            bool doubleSpace = false;
            int wordCount = 0;
            StringBuffer sb = new StringBuffer();
            if (str == null || str.Length == 0)
            {
                return null;
            }
            for (int j = 0; j < str.Length; j++)
            {
                if (str[j] == ' ')
                {
                    if (!doubleSpace)
                        wordCount++;

                    doubleSpace = true;
                    continue;
                }
                doubleSpace = false;
            }
            string[] st = new string[wordCount + 1];

            int i = 0;

            doubleSpace = false;
            string ch = "";
            for (int j = 0; j < str.Length; j++)
            {
                if (str[j] == ' ')
                {
                    if (!doubleSpace)
                    {
                        st[i] = sb.ToString();
                        sb.Delete(0, sb.Length());
                        i++;
                    }
                    doubleSpace = true;
                    continue;
                } else
                {
                    sb.Append(str[j]);
                }
                doubleSpace = false;
            }

            st[i] = sb.ToString();
            ;
            return st;
        }
开发者ID:Coopermine,项目名称:P25M_PRINTER,代码行数:57,代码来源:Util.cs

示例4: ReadLine

 /// <summary>
 /// Read a line of characters from this reader.
 /// </summary>
 /// <returns></returns>
 public virtual string ReadLine()
 {
     var buffer = new StringBuffer();
     int ch;
     while (true)
     {
         ch = Read();
         if (ch < 0)
         {
             if (buffer.Length() == 0)
                 return null;
             return buffer.ToString();
         }
         if ((ch == (int)'\n') || (ch == (int)'\r'))
         {
             break;
         }
         buffer.Append((char) ch);
     }
     if ((ch == 13) && (Peek() == 10))
     {
         Read(); // Skip
     }
     return buffer.ToString();
 }
开发者ID:sebastianhaba,项目名称:api,代码行数:29,代码来源:TextReader.cs


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