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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 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