c# 第五课 string

Strings: immutable(不可变)的unicode字符序列。

string s1 = "One Two Three Four";

string sx = (string)s1.Clone(); //s1复制到sx

Console.WriteLine(Object.ReferenceEquals(s1, sx));  //True:相同引用

sx += “ Five”;//sx修改

Console.WriteLine(Object.ReferenceEquals(s1, sx)); // False:不同的引用

Console.WriteLine(sx); // 显示"One Two Three Four Five"
 
 
ToString() method
Another common way to create a string is to call the ToString() method on an object and assign the result to astring variable.

int myInteger = 5;

string integerString = myInteger.ToString();

 

split函数  用来过滤字符串中的字符

class Program
    {
        static void Main(string[] args)
        {
            string words = "one,twot,hree,four,five";
            string[] splitedString = words.Split(',');
            foreach (string s in splitedString)
            {
                Console.Write(s);
            }
        }

 输出结果为

其中的“,”被过滤掉了。
posted @ 2015-04-19 21:23  郭松  阅读(120)  评论(0编辑  收藏  举报