string常用方法
1、Replace string替换字符串:
csharp
string st = "abcdef";
string newstring = st.Replace('a','x');
Console.WriteLine(newstring); //即:xbcdef****
csharp
string st = "abcdef";
string newstring = st.Remove(4);
Console.WriteLine(newstring); //即:abcdcsharp
string st = "abcdef";
string newstring = st.Substring(2);
Console.WriteLine(newstring); //即:cdef
public string Substring(int startIndex,int count); 从startIndex位置开始,提取count个字符。
如:
string st = "abcdef";
string newstring = st.Substring(2,2);
Console.WriteLine(newstring); //即:cdcsharp
string st = "语文|数学|英语|物理";
string[] split = st.Split(new char[]{'|'},2);
for (int i = 0; i < split.Length; i++)
{
Console.WriteLine(split[i]);
}** **
csharp
string str="";
1、if(str=="")
2、if(str==String.Empty)
3、if(str.length==0)
if(string.IsNullOrEmpty( str ))
if(str!=null&&str.length==0)csharp
string str="123456";
str.Insert(0,"x");//x123456