Nov
04

http://msdn.microsoft.com/zh-/library/ms228504.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

//如何:串联多个字符串( 编程指南)
//class stringConnect1
//{
//    static void Main()
//    {
//        string s1 = "he " + "is " + "a " + "chinese ";
//        string s2 = "boy";
//        string s3 = @"h
//                     e"+ "is";//在字符串前面加上@可以按原样输出,而不报错,若不加@则提示“常量中有换行符”
//        Console.WriteLine(s1);
//        Console.WriteLine(s1+s2);
//        Console.WriteLine(s3);
//    }
//}
//class stringConnect2
//{
//    static void Main(string[] args)
//    {
//        string name = args[0];//从命令行获取参数,,在执行程序是在后面加上参数
//        string time = DateTime.Today.ToShortDateString() ;
//        string s="您好" + name + "," + "今天是" + time;
//        //Console.WriteLine("您好" + name + "," + "今天是" + time);
//        s+=",祝您好心情!";
//        Console.WriteLine(s);
//    }
//}

//3.使用StringBuilder类的Append方法
/*如果您串联的字符串数量不那么巨大(例如,在循环中),
 * 那么这些代码的性能成本可能不会很高。上述情况同样适用于 String.Concat 和 String.Format 方法。

但如果性能的优劣很重要,则应该总是使用 StringBuilder 类来串联字符串。下面的代码使用
 * StringBuilder 类的 Append 方法来串联字符串,因此不会有 + 运算符的链接作用产生。

*/
class stringConnect
{
    static void Main()
    {

        StringBuilder s = new StringBuilder("0");
        for (int i = 1; i < 10; i++)
        {
            s.Append(i.ToString());
        }
        Console.WriteLine(s.ToString() );
    }
}

标签:,


随机文章:

最近阅读过此文章的网友:

Tags:

o(∩_∩)o1坨留言

  • Comment by ToGeekToGeek
    11月 5th, 2008 at 9:47 am

    哈哈,居然是yo2的朋友,太巧了,我是在yahoo统计看到你的,交换个链接吧,我链接你了,呵呵http://www.togeek.com

到此一游

注意: 你可以使用如下标签代码: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

| || |
由yo2提供博客服务 |Theme created by In My Pad.