好库网首页 | 我的好库
好库网 好库网社区
IT社区 » WEB开发与应用 » ASP.NET » ASP.NET字符串操作小结
回复 发帖

查看:1371    回复:0 ASP.NET字符串操作小结
访问好饱的空间
发表于 2011/4/18 12:10:01
1楼

 

1)判断字符串是否为空
string strValue = Request["xxx"];
if(string.IsNullOrEmpty(strValue) || strValue == "undefined")
   错误
2)查找字符串
int pos = IndexOf("IMG", System.StringComparison.OrdinalIgnoreCase);
if(pos >= 0)
   //找到
3)分割为数组
string[] split = words.Split(new char[] { ',', '.' });//返回:{"1","2","3","","4"}
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
4)字符串比较(忽略大小写)
string A = "aBc";
string B = "AbC";
if (string.Compare(A, B, true) == 0)
    Response.Write("一致");
else
    Response.Write("不一致");

1)判断字符串是否为空

string strValue = Request["xxx"];

if(string.IsNullOrEmpty(strValue) || strValue == "undefined")

   错误

 

2)查找字符串

int pos = IndexOf("IMG", System.StringComparison.OrdinalIgnoreCase);

if(pos >= 0)

   //找到

 

3)分割为数组

 

string[] split = words.Split(new char[] { ',', '.' });//返回:{"1","2","3","","4"}

string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素

string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

 

4)字符串比较(忽略大小写)

string A = "aBc";

string B = "AbC";

 

if (string.Compare(A, B, true) == 0)

    Response.Write("一致");

else

    Response.Write("不一致");

 

您需要登录后才可以回帖 登录 | 注册
回复 发帖