惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - leon1005

如何制作一个有颜色的ListBox,颜色选择下拉列表 获取当前程序集的物理地址 获取当前Url的主机头 获取.config文件节点的一些方法 ASP.NET 中的正则表达式 ITsun 网站流量统计被挂马。。已证实!! 禁止文本框粘贴功能(支持IE、Mozlla、FireFox等) 判断sqlserver的ntext字段是否为空的方法 存储过程里判断大小,然后赋值 请问架构高手.NET2.0的Cache和JAVA的hibernate的缓存是否类似? Cache.Insert的一些参数(.NET 1.1) 用C# 实现TCP 协议功能 Asp.net 2.0新增的缓存管理 Foreach In(C#) Cache的认识 C#导出Word Request.ServerVariables参数集 遍历浏览文件目录,并存入数据库 PetShop is Evil?
StringBuilder类的用法范例
leon1005 · 2007-09-21 · via 博客园 - leon1005

StringBuilder可以根据情况动态的调整大小,对于其它的我们在这里就不多说了,但是必须记住如果我们要使用StringBuilder,必须将using System.Text导出。下面请看一个 范例,如果掌握了这个范例里出现的方法,那么对于StringBuilder我们也就可以说能运用自如了。
范例一:
在这个范例中出现的方法为
1:Capacity
2:Length
3:Append()
4:Replace()
5:Insert()
6:Remove()
using System;
using System.Text;
namespace ConsoleApplication1
{

class Class1
{

   static void Main(string[] args)
   {
             StringBuilder sb1=new StringBuilder();
    Console.WriteLine("sb1的初始容量为:-->{0}",sb1.Capacity);
    Console.WriteLine("sb1的初始长度为:-->{0}",sb1.Length);

    sb1.Append("hello world");
    Console.WriteLine("向sb1中添加后sb1的容量为:-->{0}",sb1.Capacity);
    Console.WriteLine("向sb1中添加后sb1的长度为:-->{0}",sb1.Length);

    sb1.Append(" hello C# zhong hua ren min gong he guo ");
    Console.WriteLine("在次向sb1中添加后sb1的容量为:-->{0}",sb1.Capacity);
    Console.WriteLine("在次向sb1中添加后sb1的长度为:-->{0}",sb1.Length);

    StringBuilder sb2=new StringBuilder("I Love java",30);
    Console.WriteLine("the original text of sb2 are:");
    Console.WriteLine(sb2);
    Console.WriteLine("使用replace方法将sb2中的java换成C#后内容为:");
    Console.WriteLine(sb2.Replace("java","C#"));
             Console.WriteLine("使用insert方法在sb2第七个字符中添加'java and '后sb2的内容为");
    Console.WriteLine(sb2.Insert(7,"java and "));
    Console.WriteLine("使用remove方法将sb2中第0个字符以后的6删除后sb2的内容为:");
    Console.WriteLine(sb2.Remove(0,7));
   
   }
}
}
运行结果
sb1的初始容量为:-->16
sb1的初始长度为:-->0
向sb1中添加后sb1的容量为:-->16
向sb1中添加后sb1的长度为:-->11
在次向sb1中添加后sb1的容量为:-->52
在次向sb1中添加后sb1的长度为:-->51
the original text of sb2 are:
I Love java
使用replace方法将sb2中的java换成C#后内容为:
I Love C#
使用insert方法在sb2第七个字符中添加'java and '后sb2的内容为
I Love java and C#
使用remove方法将sb2中第0个字符以后的6删除后sb2的内容为:
java and C#
Press any key to continue