字符串
1、字符串编码转换
//这个方法将gb2312编码的字符串转为latin1(iso8859-1)编码的字符串
private string convertString(string srcString)
{
return System.Text.Encoding.GetEncoding("iso8859-1").GetString(System.Text.Encoding.GetEncoding("gb2312").GetBytes(srcString));
}
2、将字符串分割为字符串数组
string stringValue = "1,2,3,4,5,6,7,8,9,10";
string[] stringArry = stringValue.Split(',');
3、在字符串指定位置插入指定字符
string a = "abc.gif";
string b = a.Inert(a.LastIndexOf('.'),"_");
//b的结果为:abc_.gif
4、截取文件扩展名
string fileName = "abcdefg123456.jpg";
string result = fileName.Substring(fileName.LastIndexOf(".")+1);
//result的结果为jpg