字符串常用方法

string str =""; string[] strarray = str.split('截取字符'); //按字符将字符串拆分为数组 str = str.replace("n","m");//将字符串n替换为m str = str.remove(i,length);//删除字符串下标i,长度为8下标从0开始 str = str.substring(n); //截取字符串,下标充0开始,包括n bool bl = string.isnullorempty(str)//判断str是否为""和nul,返回true为""或者null bool bl = str.contains("n"); //判断字符串str里面是否包含"n",返回true包含,false不包含 bool bl = str.equals(str1);//判断字符串str和字符串str1是否完全一样(区分大小写) 返回true完全一样 int index = str.indexof("n"); int index = str.lastindexof("n"); //indexof 和 lastindexof 判断字符串第一次出现(indexof)和最后一次出现(lastindexof)的位置,如果没有出现过则返回值为-1

string s=str.insert(index,"")//在字符串的index位置上插入字符,原来的字符依次后移,变成一个新的字符串 char[] s=str.tochararray();//tochararray将字符串转化为字符数组(<string>.tochararray()) str = str.trim();// 去掉前后两边的空格 str=str.toupper();//转换为大写 str=str.tolower();//转换为小写 //toupper(转换为大写)和tolower(转换为小写)