C# 基础入门 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

方法


  String 类有许多方法用于 string 对象的操作,在这里给同学们简要介绍几个:

public string Remove( int startIndex ) 移除当前实例中的所有字符,从指定位置开始,一直到最后一个位置为止,并返回字符串。

public string Remove( int startIndex, int count ) 从当前字符串的指定位置开始移除指定数量的字符,并返回字符串。

public string Replace( string oldValue, string newValue ) 把当前 string 对象中,所有指定的字符串替换为另一个指定的字符串,并返回新的字符串。

public string[] Split( char[] separator, int count ) 返回一个字符串数组,包含当前的 string 对象中的子字符串,子字符串是使用指定的 Unicode 字符数组中的元素进行分隔的。int 参数指定要返回的子字符串的最大数目。

public string ToLower() 把字符串转换为小写并返回。

public string ToUpper() 把字符串转换为大写并返回。

public string Trim() 移除当前 String 对象中的所有前导空白字符和后置空白字符。

string s="  hello world!  ";
s=s.ToUpper();
s=s.Trim();
Console.WriteLine(s);  //输出大写HELLO WORLD!