///
/// 获得字符串中开始和结束字符串中间得值
///
///
/// 开始
/// 结束
///
public static string GetValue(string str, string s, string e)
{
Regex rg = new Regex("(?<=(" + s + "))[.sS]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(str).Value;
}
///
/// 截取字符串过多+……
///
/// 字符串
/// 长度
/// string
public static string CutString(string inputString, int len)
{
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(inputString);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
} try
{
tempString += inputString.Substring(i, 1);
}
catch
{
break;
} if (tempLen > len)
break;
}
//如果截过则加上半个省略号
byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString);
if (mybyte.Length > len)
tempString += "…"; return tempString;
}
|