zoukankan      html  css  js  c++  java
  • 替换字符串和更改大小写

    替换字符串 :

    为了替换字符串中特定的子字符串,可以使用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);

  • 相关阅读:
    第七讲 宋词:婉约之曲与豪放之声
    P2024 食物链
    可以吹一年的事
    信息传递
    11.11模拟赛总结(又名斗地主战记)
    11.9模拟赛总结
    扩展欧几里得(exgcd模板)
    发糖果(拓扑排序模板)
    高斯消元
    关于我
  • 原文地址:https://www.cnblogs.com/lichen396116416/p/1920484.html
Copyright © 2011-2022 走看看