替换字符串 :

为了替换字符串中特定的子字符串,可以使用String类中的Replace方法,该方法有两个重载

    public string Replace (string oldValue ,string newValue)

其中将实例字符串中的oldValue 字符串替换为 newVlaue的字符串

public string Replace(char oldChar ,char newChar)

代码:

string str = "这是要被替换的原字符串";
                Console.WriteLine(str);
                Console.WriteLine("----------------------------");
                string str2 = str.Replace("要被替换的原字符串", "已经被替换的字符串");
                Console.WriteLine(str2);
           

 

更改大小写

 String 类中提供了ToUpper和Tolower 方法可以执行大小写的转换

String.Toupper 返回String 转换为大写形式的副本 

string .Toliwer  返回String转换为小写的形式的副本。

代码:

string str = "Hello,World";
                string str2 = str.ToUpper();
                Console.WriteLine("转换为大写以后的结果为:{0}",str2);
                string str3 = str.ToLower();
                Console.WriteLine("转换为小写以后的结果为:{0}", str3);

Posted on 2010-12-29 12:02  lichen396116416  阅读(478)  评论(0编辑  收藏  举报