经常要合成url,每次用每次写,很麻烦。写成了一个静态方法方便一点。很简单的功能。废话少说了。
///
/// 判断string是否合法。长度为空,或null 不合法
///
///
public static bool IsStringNull(string strcheck)
{
if (strcheck == null || strcheck.Trim().Length <= 0)
{
return true;
}
else
return false;
}
///
/// 给url添加参数
///
///demo: http://www.google.cn/search?keyword=good&type=1
/// 原strUrl的值不带问号。
/// demo:http://www.google.cn/search
///
/// 参数的名字
/// demo:"keyword" 或 "type"
/// 参数的值
/// demo:"good" 或 "1"
///
public static string UrlAddParam(string strUrl,string param,string value)
{
if (IsStringNull(strUrl))
{
return null;
}
if (IsStringNull(param) || IsStringNull(value))
{
;//do nothing
}
else
{
if (strUrl.IndexOf("?") == -1)
strUrl = strUrl + "?" + param + "=" + value;
else
{
strUrl = strUrl + "&" + param + "=" + value;
}
}
return strUrl;
}