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


C# StringBuilder.Append方法代码示例

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


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

示例1:

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 16-bit unsigned integer: ");
sb.Append(UInt16.MinValue).Append(" to ").Append(UInt16.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of a 16-bit unsigned integer: 0 to 65535

示例2:

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 32-bit unsigned integer: ");
sb.Append(UInt32.MinValue).Append(" to ").Append(UInt32.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of a 32-bit unsigned integer: 0 to 4294967295

示例3:

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of a 64-bit unsigned integer: ");
sb.Append(UInt64.MinValue).Append(" to ").Append(UInt64.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of a 64-bit unsigned integer: 0 to 18446744073709551615

示例4: if

char[] chars = { 'a', 'b', 'c', 'd', 'e'};
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int startPosition = Array.IndexOf(chars, 'a');
int endPosition = Array.IndexOf(chars, 'c');
if (startPosition >= 0 && endPosition >= 0) {
   sb.Append("The array from positions ").Append(startPosition).
             Append(" to ").Append(endPosition).Append(" contains ").
             Append(chars, startPosition, endPosition + 1).Append(".");
   Console.WriteLine(sb);
}
开发者ID:.NET开发者,项目名称:System.Text,代码行数:10,代码来源:StringBuilder.Append

输出:

The array from positions 0 to 2 contains abc.

示例5:

bool flag = false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The value of the flag is ").Append(flag).Append(".");
Console.WriteLine(sb.ToString());
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The value of the flag is False.

示例6:

string str = "First;George Washington;1789;1797";
int index = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int length = str.IndexOf(';', index);      
sb.Append(str, index, length).Append(" President of the United States: ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(", from ");
index += length + 1;
length = str.IndexOf(';', index) - index;
sb.Append(str, index, length).Append(" to ");
index += length + 1;
sb.Append(str, index, str.Length - index);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:14,代码来源:StringBuilder.Append

输出:

First President of the United States: George Washington, from 1789 to 1797

示例7:

decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).AppendFormat("{0:C2}", value).Append('*', 5);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

*****$1,346.19*****

示例8:

System.Text.StringBuilder sb = new 
            System.Text.StringBuilder("The range of an 8-bit signed integer: ");
sb.Append(SByte.MinValue).Append(" to ").Append(SByte.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of an 8-bit unsigned integer: -128 to 127

示例9:

float value = 1034769.47f;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

*****1034769.47*****

示例10: foreach

string str = "Characters in a string.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var ch in str)
   sb.Append(" '").Append(ch).Append("' ");

Console.WriteLine("Characters in the string:");
Console.WriteLine("  {0}", sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:7,代码来源:StringBuilder.Append

输出:

Characters in the string:
'C'  'h'  'a'  'r'  'a'  'c'  't'  'e'  'r'  's'  ' '  'i'  'n'  ' '  'a'  ' '  's'  't' 'r'  'i'  'n'  'g'  '.'

示例11:

char[] chars = { 'a', 'e', 'i', 'o', 'u' };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("The characters in the array: ").Append(chars);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The characters in the array: aeiou

示例12:

decimal value = 1346.19m;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append('*', 5).Append(value).Append('*', 5);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

*****1346.19*****

示例13: foreach

Byte[] bytes = { 16, 132, 27, 253 };
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var value in bytes)
   sb.Append(value).Append(" ");         

Console.WriteLine("The byte array: {0}", sb.ToString());
开发者ID:.NET开发者,项目名称:System.Text,代码行数:6,代码来源:StringBuilder.Append

输出:

The byte array: 16 132 27 253

示例14:

System.Text.StringBuilder sb = new 
       System.Text.StringBuilder("The range of a 16-bit integer: ");
sb.Append(Int16.MinValue).Append(" to ").Append(Int16.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of a 16-bit integer: -32768 to 32767

示例15:

System.Text.StringBuilder sb = new 
       System.Text.StringBuilder("The range of a 32-bit integer: ");
sb.Append(Int32.MinValue).Append(" to ").Append(Int32.MaxValue);
Console.WriteLine(sb);
开发者ID:.NET开发者,项目名称:System.Text,代码行数:4,代码来源:StringBuilder.Append

输出:

The range of a 32-bit integer: -2147483648 to 2147483647


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