如何创建stringbuilder [英] How to create stringbuilder
本文介绍了如何创建stringbuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建字符串构建器示例
请帮助我
How to create a string builder example
please help me
推荐答案
MSDN示例有什么问题?
http://msdn.microsoft.com/en-us/library/system.text. stringbuilder.aspx [ ^ ]
以下代码是从MSDN复制粘贴的:
Whats the Problem with the MSDN Example?
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx[^]
Following Code is Copy Pasted from MSDN:
using System;
using System.Text;
public sealed class App
{
static void Main()
{
// Create a StringBuilder that expects to hold 50 characters.
// Initialize the StringBuilder with "ABC".
StringBuilder sb = new StringBuilder("ABC", 50);
// Append three characters (D, E, and F) to the end of the StringBuilder.
sb.Append(new char[] { 'D', 'E', 'F' });
// Append a format string to the end of the StringBuilder.
sb.AppendFormat("GHI{0}{1}", 'J', 'k');
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
// Insert a string at the beginning of the StringBuilder.
sb.Insert(0, "Alphabet: ");
// Replace all lowercase k's with uppercase K's.
sb.Replace('k', 'K');
// Display the number of characters in the StringBuilder and its string.
Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
}
}
// This code produces the following output.
//
// 11 chars: ABCDEFGHIJk
// 21 chars: Alphabet: ABCDEFGHIJK
System.Text.Stringbuilder sb = new System.Text.Stringbuilder;
sb.AppendLine("TEST1");
sb.AppendLine("TEST2");
sb.AppendLine("TEST3");
sb.AppendLine("TEST4");
String str = new String;
str = sb.ToString;
请参考此 [
Hi,
refer this[^] it will help u lot
Best Luck
这篇关于如何创建stringbuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文