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


C# StringBuilder.toString方法代码示例

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


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

示例1: reverseWords

    // A2: reverse the whole string, detect each word and reverse the word
    // Pitfall: need extra work to remove continuous space
    public String reverseWords(String input)
    {
        if (input==null || input.length() == 0) return input;
        StringBuilder a = new StringBuilder(input);

        int start = -1;
        int end = -1;

        reverse(a, 0, a.length()-1);

        for (int i=0; i<=a.length(); i++)
        {
            if (i == a.length() || a.charAt(i) == ' ')
            {
                if (start < end) reverse(a, start+1, end);
                start = i;
            }
            else
            {
                end = i;
            }
        }

        return a.toString();
    }
开发者ID:hsn6,项目名称:training,代码行数:27,代码来源:FB_Revword.cs

示例2: getMessage

 /**
  * Returns the message string of the DuplicateFormatFlagsException.
  *
  * @return the message string of the DuplicateFormatFlagsException.
  */
 public override String getMessage()
 {
     StringBuilder buffer = new StringBuilder();
     buffer.append("Flags of the DuplicateFormatFlagsException is'");
     buffer.append(flags);
     buffer.append("'");
     return buffer.toString();
 }
开发者ID:gadfly,项目名称:nofs,代码行数:13,代码来源:java.util.DuplicateFormatFlagsExceptions.cs

示例3: GetFailQueries

 public static string GetFailQueries(string[] exceptionQueries, bool verbose)
 {
     StringBuilder failQueries = new StringBuilder();
     for (int i = 0; i < exceptionQueries.Length; i++)
     {
         new ExceptionQueryTst(exceptionQueries[i], verbose).DoTest(failQueries);
     }
     return failQueries.toString();
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:9,代码来源:ExceptionQueryTst.cs

示例4: generateFileInput

 private KeyValuePair<List<List<string>>, string> generateFileInput(int count, string fieldDelimiter, bool hasWeights, bool hasPayloads)
 {
     List<List<string>> entries = new List<List<string>>();
     StringBuilder sb = new StringBuilder();
     bool hasPayload = hasPayloads;
     for (int i = 0; i < count; i++)
     {
         if (hasPayloads)
         {
             hasPayload = (i == 0) ? true : Random().nextBoolean();
         }
         KeyValuePair<List<string>, string> entrySet = GenerateFileEntry(fieldDelimiter, (!hasPayloads && hasWeights) ? Random().nextBoolean() : hasWeights, hasPayload);
         entries.Add(entrySet.Key);
         sb.append(entrySet.Value);
     }
     return new KeyValuePair<List<List<string>>, string>(entries, sb.toString());
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:17,代码来源:FileDictionaryTest.cs

示例5: toASCIILowerCase

 public static String toASCIILowerCase(String s)
 {
     int len = s.length();
     StringBuilder buffer = new StringBuilder(len);
     for (int i = 0; i < len; i++)
     {
         char c = s.charAt(i);
         if ('A' <= c && c <= 'Z')
         {
             buffer.append((char)(c + ('a' - 'A')));
         }
         else
         {
             buffer.append(c);
         }
     }
     return buffer.toString();
 }
开发者ID:gadfly,项目名称:nofs,代码行数:18,代码来源:org.apache.harmony.luni.util.Util.cs

示例6: GenerateFileEntry

 private KeyValuePair<List<string>, string> GenerateFileEntry(string fieldDelimiter, bool hasWeight, bool hasPayload)
 {
     List<string> entryValues = new List<string>();
     StringBuilder sb = new StringBuilder();
     string term = TestUtil.RandomSimpleString(Random(), 1, 300);
     sb.append(term);
     entryValues.Add(term);
     if (hasWeight)
     {
         sb.append(fieldDelimiter);
         long weight = TestUtil.NextLong(Random(), long.MinValue, long.MaxValue);
         sb.append(weight);
         entryValues.Add(weight.ToString());
     }
     if (hasPayload)
     {
         sb.append(fieldDelimiter);
         string payload = TestUtil.RandomSimpleString(Random(), 1, 300);
         sb.append(payload);
         entryValues.Add(payload);
     }
     sb.append("\n");
     return new KeyValuePair<List<string>, string>(entryValues, sb.toString());
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:24,代码来源:FileDictionaryTest.cs

示例7: quoteIllegal

        internal const String encoding = "utf-8"; //$NON-NLS-1$

        #endregion Fields

        #region Methods

        /**
         * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
         * and legal characters are converted into their hexidecimal value prepended
         * by '%'.
         * <p>
         * For example: '#' -> %23
         * Other characters, which are unicode chars that are not US-ASCII, and are
         * not ISO Control or are not ISO Space chars, are preserved.
         * <p>
         * Called from {@code URI.quoteComponent()} (for multiple argument
         * constructors)
         *
         * @param s
         *            java.lang.String the string to be converted
         * @param legal
         *            java.lang.String the characters allowed to be preserved in the
         *            string s
         * @return java.lang.String the converted string
         */
        internal static String quoteIllegal(String s, String legal)
        {
            //throws UnsupportedEncodingException {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if ((ch >= 'a' && ch <= 'z')
                        || (ch >= 'A' && ch <= 'Z')
                        || (ch >= '0' && ch <= '9')
                        || legal.indexOf(ch) > -1
                        || (ch > 127 && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character
                                .isISOControl(ch))) {
                    buf.append(ch);
                } else {
                    byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
                    for (int j = 0; j < bytes.Length; j++) {
                        buf.append('%');
                        buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                        buf.append(digits.charAt(bytes[j] & 0xf));
                    }
                }
            }
            return buf.toString();
        }
开发者ID:gadfly,项目名称:nofs,代码行数:49,代码来源:java.net.URIEncoderDecoder.cs

示例8: parseNumber

	    /**
	     * Parses <code>source</code> for special double values.  These values
	     * include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
	     *
	     * @param source the string to parse
	     * @param value the special value to parse.
	     * @param pos input/ouput parsing parameter.
	     * @return the special number.
	     */
	    private static Number parseNumber(String source, double value,
	                                      ParsePosition pos) {
	        Number ret = null;
	
	        StringBuilder sb = new StringBuilder();
	        sb.append('(');
	        sb.append(value);
	        sb.append(')');
	
	        int n = sb.length();
	        int startIndex = pos.getIndex();
	        int endIndex = startIndex + n;
	        if (endIndex < source.length()) {
	            if (source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) {
	                ret = Double.valueOf(value);
	                pos.setIndex(endIndex);
	            }
	        }
	
	        return ret;
	    }
开发者ID:HankG,项目名称:Apache.Commons.Math,代码行数:30,代码来源:CompositeFormat.cs

示例9: ToString

 /**
  * Returns a string containing a concise, human-readable description of the
  * receiver.
  *
  * @return a comma delimited list of the indices of all bits that are set.
  */
 public override String ToString()
 {
     StringBuilder sb = new StringBuilder(bits.Length / 2);
     int bitCount = 0;
     sb.append('{');
     bool comma = false;
     for (int i = 0; i < bits.Length; i++) {
         if (bits[i] == 0) {
             bitCount += ELM_SIZE;
             continue;
         }
         for (int j = 0; j < ELM_SIZE; j++) {
             if (((bits[i] & (TWO_N_ARRAY[j])) != 0)) {
                 if (comma) {
                     sb.append(", "); //$NON-NLS-1$
                 }
                 sb.append(bitCount);
                 comma = true;
             }
             bitCount++;
         }
     }
     sb.append('}');
     return sb.toString();
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:31,代码来源:BitSet.cs

示例10: toDecimalScaledString

        /**
         * Builds the correspondent {@code String} representation of {@code val}
         * being scaled by {@code scale}.
         *
         * @see BigInteger#toString()
         * @see BigDecimal#toString()
         */
        internal static String toDecimalScaledString(BigInteger val, int scale)
        {
            int sign = val.sign;
            int numberLength = val.numberLength;
            int []digits = val.digits;
            int resLengthInChars;
            int currentChar;
            char []result;

            if (sign == 0) {
                switch (scale) {
                    case 0:
                        return "0"; //$NON-NLS-1$
                    case 1:
                        return "0.0"; //$NON-NLS-1$
                    case 2:
                        return "0.00"; //$NON-NLS-1$
                    case 3:
                        return "0.000"; //$NON-NLS-1$
                    case 4:
                        return "0.0000"; //$NON-NLS-1$
                    case 5:
                        return "0.00000"; //$NON-NLS-1$
                    case 6:
                        return "0.000000"; //$NON-NLS-1$
                    default:
                        StringBuilder result0 = new StringBuilder();
                        if (scale < 0) {
                            result0.Append("0E+"); //$NON-NLS-1$
                        } else {
                            result0.Append("0E"); //$NON-NLS-1$
                        }
                        result0.Append(-scale);
                        return result0.toString();
                }
            }
            // one 32-bit unsigned value may contains 10 decimal digits
            resLengthInChars = numberLength * 10 + 1 + 7;
            // Explanation why +1+7:
            // +1 - one char for sign if needed.
            // +7 - For "special case 2" (see below) we have 7 free chars for
            // inserting necessary scaled digits.
            result = new char[resLengthInChars + 1];
            // allocated [resLengthInChars+1] characters.
            // a free latest character may be used for "special case 1" (see
            // below)
            currentChar = resLengthInChars;
            if (numberLength == 1) {
                int highDigit = digits[0];
                if (highDigit < 0) {
                    long v = highDigit & 0xFFFFFFFFL;
                    do {
                        long prev = v;
                        v /= 10;
                        result[--currentChar] = (char) (0x0030 + ((int) (prev - v * 10)));
                    } while (v != 0);
                } else {
                    int v = highDigit;
                    do {
                        int prev = v;
                        v /= 10;
                        result[--currentChar] = (char) (0x0030 + (prev - v * 10));
                    } while (v != 0);
                }
            } else {
                int []temp = new int[numberLength];
                int tempLen = numberLength;
                java.lang.SystemJ.arraycopy(digits, 0, temp, 0, tempLen);
                /*BIG_LOOP: */while (true) {
                    // divide the array of digits by bigRadix and convert
                    // remainders
                    // to characters collecting them in the char array
                    long result11 = 0;
                    for (int i1 = tempLen - 1; i1 >= 0; i1--) {
                        long temp1 = (result11 << 32)
                                + (temp[i1] & 0xFFFFFFFFL);
                        long res = divideLongByBillion(temp1);
                        temp[i1] = (int) res;
                        result11 = (int) (res >> 32);
                    }
                    int resDigit = (int) result11;
                    int previous = currentChar;
                    do {
                        result[--currentChar] = (char) (0x0030 + (resDigit % 10));
                    } while (((resDigit /= 10) != 0) && (currentChar != 0));
                    int delta = 9 - previous + currentChar;
                    for (int i = 0; (i < delta) && (currentChar > 0); i++) {
                        result[--currentChar] = '0';
                    }
                    int j = tempLen - 1;
                    for (; temp[j] == 0; j--) {
                        if (j == 0) { // means temp[0] == 0
                            goto AFTER_LOOP; //break BIG_LOOP;
//.........这里部分代码省略.........
开发者ID:sailesh341,项目名称:JavApi,代码行数:101,代码来源:Conversion.cs

示例11: readLine

        //throws IOException
        /**
         * Returns the next line of text available from this reader. A line is
         * represented by zero or more characters followed by {@code '\n'},
         * {@code '\r'}, {@code "\r\n"} or the end of the reader. The string does
         * not include the newline sequence.
         *
         * @return the contents of the line or {@code null} if no characters were
         *         read before the end of the reader has been reached.
         * @throws IOException
         *             if this reader is closed or some other I/O error occurs.
         */
        public virtual String readLine()
        {
            lock (lockJ) {
                if (isClosed()) {
                    throw new IOException(MESSAGE_READER_IS_CLOSED); //$NON-NLS-1$
                }
                /* has the underlying stream been exhausted? */
                if (pos == end && fillBuf() == -1) {
                    return null;
                }
                for (int charPos = pos; charPos < end; charPos++) {
                    char ch = buf[charPos];
                    if (ch > '\r') {
                        continue;
                    }
                    if (ch == '\n') {
                        String res = new String(buf, pos, charPos - pos);
                        pos = charPos + 1;
                        return res;
                    } else if (ch == '\r') {
                        String res = new String(buf, pos, charPos - pos);
                        pos = charPos + 1;
                        if (((pos < end) || (fillBuf() != -1))
                                && (buf[pos] == '\n')) {
                            pos++;
                        }
                        return res;
                    }
                }

                char eol = '\0';
                StringBuilder result = new StringBuilder(80);
                /* Typical Line Length */

                result.Append(buf, pos, end - pos);
                while (true) {
                    pos = end;

                    /* Are there buffered characters available? */
                    if (eol == '\n') {
                        return result.toString();
                    }
                    // attempt to fill buffer
                    if (fillBuf() == -1) {
                        // characters or null.
                        return result.Length > 0 || eol != '\0'
                                ? result.toString()
                                : null;
                    }
                    for (int charPos = pos; charPos < end; charPos++) {
                        char c = buf[charPos];
                        if (eol == '\0') {
                            if ((c == '\n' || c == '\r')) {
                                eol = c;
                            }
                        } else if (eol == '\r' && c == '\n') {
                            if (charPos > pos) {
                                result.Append(buf, pos, charPos - pos - 1);
                            }
                            pos = charPos + 1;
                            return result.toString();
                        } else {
                            if (charPos > pos) {
                                result.Append(buf, pos, charPos - pos - 1);
                            }
                            pos = charPos;
                            return result.toString();
                        }
                    }
                    if (eol == '\0') {
                        result.Append(buf, pos, end - pos);
                    } else {
                        result.Append(buf, pos, end - pos - 1);
                    }
                }
            }
        }
开发者ID:gadfly,项目名称:nofs,代码行数:89,代码来源:java.io.BufferedReader.cs

示例12: toUri

        /// <summary>
        /// Encode this Exclude with elements separated by "," and Exclude.Type.ANY
        /// shown as "///".
        /// </summary>
        ///
        /// <returns>the URI string</returns>
        public String toUri()
        {
            if ((entries_.Count==0))
                return "";

            StringBuilder result = new StringBuilder();
            for (int i = 0; i < entries_.Count; ++i) {
                if (i > 0)
                    result.append(",");

                if (get(i).getType() == net.named_data.jndn.Exclude.Type.ANY)
                    result.append("*");
                else
                    get(i).getComponent().toEscapedString(result);
            }

            return result.toString();
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:24,代码来源:Exclude.cs

示例13: getListData

        /// <summary>
        /// 获取分页数据
        /// </summary>
        public string getListData(TDemoModel searchModel = null)
        {
            StringBuilder sb = new StringBuilder();
            string searchText = "";
            //检索
            StringBuilder searchScript = new StringBuilder();
            searchScript.AppendLine(" WHERE ");
            searchScript.AppendLine(" 1 = 1 ");
            if (!String.IsNullOrEmpty(searchModel.fullTextSearch))
            {
                searchScript.AppendLine(" AND ( ");
                searchScript.AppendLine("     [Column1] LIKE N'%" + searchModel.fullTextSearch.quote() + "%'");
                searchScript.AppendLine("     OR [Column2] = '" + searchModel.fullTextSearch.quote() + "'");
                searchScript.AppendLine("     OR [Column3] = '" + searchModel.fullTextSearch.quote() + "'");
                searchScript.AppendLine("     OR [Column4] = '" + searchModel.fullTextSearch.quote() + "'");
                searchScript.AppendLine(" ) ");
            }
            searchText = searchScript.toString();

            //获取总数据量
            sb.AppendLine(" DECLARE @dataCount int ");
            sb.AppendLine("  ");
            sb.AppendLine(" SELECT ");
            sb.AppendLine(" @dataCount = COUNT(1) ");
            sb.AppendLine(" FROM [dbo].[TDemo]");
            sb.AppendLine(searchText);
            sb.Append(" ; ");

            //数据分页
            sb.AppendLine(" WITH TMP AS ( ");
            sb.AppendLine(" SELECT ");
            sb.AppendLine(" [ID] ");
            sb.AppendLine(" ,[Column1] ");
            sb.AppendLine(" ,[Column2] ");
            sb.AppendLine(" ,[Column3] ");
            sb.AppendLine(" ,[Column4] ");
            sb.AppendLine(" ,ROW_NUMBER() OVER(" + string.Format("ORDER BY {0} {1}",
                                                    searchModel.sortColumn,
                                                    searchModel.sortDirection == System.ComponentModel.ListSortDirection.Ascending ? "ASC" : "DESC")
                                                + ") AS [RowNumber] ");
            sb.AppendLine(" FROM [dbo].[TDemo]");
            sb.AppendLine(searchText);
            sb.AppendLine(" ) ");

            //获取分页数据
            sb.AppendLine(" SELECT ");
            sb.AppendLine(" A.[ID] ");
            sb.AppendLine(" ,A.[Column1] ");
            sb.AppendLine(" ,A.[Column2] ");
            sb.AppendLine(" ,A.[Column3] ");
            sb.AppendLine(" ,A.[Column4] ");
            sb.AppendLine(" ,@dataCount AS [DataCount] ");
            sb.AppendLine(" FROM TMP AS A ");
            if (searchModel != null)
            {
                sb.AppendLine(" WHERE ");
                sb.AppendLine(" 1 = 1 ");
                sb.AppendLine(string.Format(" AND A.[RowNumber] BETWEEN {0} AND {1} ", searchModel.startRowNumber, searchModel.endRowNumber));
            }

            if (searchModel != null && !Check.getIns().isEmpty(searchModel.sortColumn))
            {
                sb.AppendLine(string.Format("ORDER BY A.{0} {1}",
                    searchModel.sortColumn,
                    searchModel.sortDirection == System.ComponentModel.ListSortDirection.Ascending ? "ASC" : "DESC"));
            }
            return sb.ToString();
        }
开发者ID:Lugia123,项目名称:XLugia.XDatabase,代码行数:71,代码来源:TDemoScript.cs

示例14: ToString

 /**
  * Returns the state of this tokenizer in a readable format.
  *
  * @return the current state of this tokenizer.
  */
 public override String ToString()
 {
     // Values determined through experimentation
     StringBuilder result = new StringBuilder();
     result.append("Token["); //$NON-NLS-1$
     switch (ttype) {
         case TT_EOF:
             result.append("EOF"); //$NON-NLS-1$
             break;
         case TT_EOL:
             result.append("EOL"); //$NON-NLS-1$
             break;
         case TT_NUMBER:
             result.append("n="); //$NON-NLS-1$
             result.append(nval);
             break;
         case TT_WORD:
             result.append(sval);
             break;
         default:
             if (ttype == TT_UNKNOWN || tokenTypes[ttype] == TOKEN_QUOTE) {
                 result.append(sval);
             } else {
                 result.append('\'');
                 result.append((char) ttype);
                 result.append('\'');
             }
             break;
     }
     result.append("], line "); //$NON-NLS-1$
     result.append(lineNumber);
     return result.toString();
 }
开发者ID:gadfly,项目名称:nofs,代码行数:38,代码来源:java.io.StreamTokenizer.cs

示例15: nextToken

        /**
         * Parses the next token from this tokenizer's source stream or reader. The
         * type of the token is stored in the {@code ttype} field, additional
         * information may be stored in the {@code nval} or {@code sval} fields.
         *
         * @return the value of {@code ttype}.
         * @throws IOException
         *             if an I/O error occurs while parsing the next token.
         */
        public virtual int nextToken()
        {
            // throws IOException {
            if (pushBackToken) {
                pushBackToken = false;
                if (ttype != TT_UNKNOWN) {
                    return ttype;
                }
            }
            sval = null; // Always reset sval to null
            int currentChar = peekChar == -2 ? read() : peekChar;

            if (lastCr && currentChar == '\n') {
                lastCr = false;
                currentChar = read();
            }
            if (currentChar == -1) {
                return (ttype = TT_EOF);
            }

            byte currentType = currentChar > 255 ? TOKEN_WORD
                    : tokenTypes[currentChar];
            while ((currentType & TOKEN_WHITE) != 0) {
                /**
                 * Skip over white space until we hit a new line or a real token
                 */
                if (currentChar == '\r') {
                    lineNumber++;
                    if (isEOLSignificant) {
                        lastCr = true;
                        peekChar = -2;
                        return (ttype = TT_EOL);
                    }
                    if ((currentChar = read()) == '\n') {
                        currentChar = read();
                    }
                } else if (currentChar == '\n') {
                    lineNumber++;
                    if (isEOLSignificant) {
                        peekChar = -2;
                        return (ttype = TT_EOL);
                    }
                    currentChar = read();
                } else {
                    // Advance over this white space character and try again.
                    currentChar = read();
                }
                if (currentChar == -1) {
                    return (ttype = TT_EOF);
                }
                currentType = currentChar > 255 ? TOKEN_WORD
                        : tokenTypes[currentChar];
            }

            /**
             * Check for digits before checking for words since digits can be
             * contained within words.
             */
            if ((currentType & TOKEN_DIGIT) != 0) {
                StringBuilder digits = new StringBuilder(20);
                bool haveDecimal = false, checkJustNegative = currentChar == '-';
                while (true) {
                    if (currentChar == '.') {
                        haveDecimal = true;
                    }
                    digits.append((char) currentChar);
                    currentChar = read();
                    if ((currentChar < '0' || currentChar > '9')
                            && (haveDecimal || currentChar != '.')) {
                        break;
                    }
                }
                peekChar = currentChar;
                if (checkJustNegative && digits.Length == 1) {
                    // Didn't get any other digits other than '-'
                    return (ttype = '-');
                }
                try {
                    nval = java.lang.Double.valueOf(digits.toString()).doubleValue();
                } catch (java.lang.NumberFormatException e) {
                    // Unsure what to do, will write test.
                    nval = 0;
                }
                return (ttype = TT_NUMBER);
            }
            // Check for words
            if ((currentType & TOKEN_WORD) != 0) {
                StringBuilder word = new StringBuilder(20);
                while (true) {
                    word.append((char) currentChar);
                    currentChar = read();
//.........这里部分代码省略.........
开发者ID:gadfly,项目名称:nofs,代码行数:101,代码来源:java.io.StreamTokenizer.cs


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