博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 函数3
阅读量:4882 次
发布时间:2019-06-11

本文共 15723 字,大约阅读时间需要 52 分钟。

//获取部分

    
public 
class 
GF_GET
    
{
        
/// <summary>
        
/// 根据坐标点获取屏幕图像
        
/// </summary>
        
/// <param name="x1">左上角横坐标</param>
        
/// <param name="y1">左上角纵坐标</param>
        
/// <param name="x2">右下角横坐标</param>
        
/// <param name="y2">右下角纵坐标</param>
        
/// <returns></returns>
        
public 
static 
Image GetScreen(
int 
x1, 
int 
y1, 
int 
x2, 
int 
y2)
        
{
            
int 
w = (x2 - x1);
            
int 
h = (y2 - y1);
            
Image myImage = 
new 
Bitmap(w, h);
            
Graphics g = Graphics.FromImage(myImage);
            
g.CopyFromScreen(
new 
Point(x1, y1), 
new 
Point(0, 0), 
new 
Size(w, h));
            
IntPtr dc1 = g.GetHdc();
            
g.ReleaseHdc(dc1);
            
return 
myImage;
        
}
 
        
/// <summary>
        
/// 获取指定文件的扩展名 例:  .txt
        
/// </summary>
        
/// <param name="fileName">指定文件名</param>
        
/// <returns>扩展名</returns>
        
public 
static 
string 
GetFileExtName(
string 
fileName)
        
{
            
if 
(GF_IsOk.IsStrNullOrEmpty(fileName) || fileName.IndexOf(
'.'
) <= 0)
                
return 
""
;
             
            
fileName = fileName.ToLower().Trim();       
 
             
            
return 
fileName.Substring(fileName.LastIndexOf(
'.'
), fileName.Length - fileName.LastIndexOf(
'.'
));
        
}
 
        
public 
static 
string 
GetSubString(
string 
p_SrcString, 
int 
p_Length, 
string 
p_TailString)
        
{
            
return 
GetSubString(p_SrcString, 0, p_Length, p_TailString);
        
}
 
        
public 
static 
string 
GetUnicodeSubString(
string 
str, 
int 
len, 
string 
p_TailString)
        
{
            
string 
result = 
string
.Empty;
// 最终返回的结果
            
int 
byteLen = System.Text.Encoding.Default.GetByteCount(str);
// 单字节字符长度
            
int 
charLen = str.Length;
// 把字符平等对待时的字符串长度
            
int 
byteCount = 0;
// 记录读取进度
            
int 
pos = 0;
// 记录截取位置
            
if 
(byteLen > len)
            
{
                
for 
(
int 
i = 0; i < charLen; i++)
                
{
                    
if 
(Convert.ToInt32(str.ToCharArray()[i]) > 255)
// 按中文字符计算加2
                        
byteCount += 2;
                    
else
// 按英文字符计算加1
                        
byteCount += 1;
                    
if 
(byteCount > len)
// 超出时只记下上一个有效位置
                    
{
                        
pos = i;
                        
break
;
                    
}
                    
else 
if 
(byteCount == len)
// 记下当前位置
                    
{
                        
pos = i + 1;
                        
break
;
                    
}
                
}
 
                
if 
(pos >= 0)
                    
result = str.Substring(0, pos) + p_TailString;
            
}
            
else
                
result = str;
 
            
return 
result;
        
}
 
        
/// <summary>
        
/// 取指定长度的字符串
        
/// </summary>
        
/// <param name="p_SrcString">要检查的字符串</param>
        
/// <param name="p_StartIndex">起始位置</param>
        
/// <param name="p_Length">指定长度</param>
        
/// <param name="p_TailString">用于替换的字符串</param>
        
/// <returns>截取后的字符串</returns>
        
public 
static 
string 
GetSubString(
string 
p_SrcString, 
int 
p_StartIndex, 
int 
p_Length, 
string 
p_TailString)
        
{
            
string 
myResult = p_SrcString;
 
            
Byte[] bComments = Encoding.UTF8.GetBytes(p_SrcString);
            
foreach 
(
char 
in 
Encoding.UTF8.GetChars(bComments))
            
{    
//当是日文或韩文时(注:中文的范围:\u4e00 - \u9fa5, 日文在\u0800 - \u4e00, 韩文为\xAC00-\xD7A3)
                
if 
((c > 
'\u0800' 
&& c < 
'\u4e00'
) || (c > 
'\xAC00' 
&& c < 
'\xD7A3'
))
                
{
                    
//if (System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\u0800-\u4e00]+") || System.Text.RegularExpressions.Regex.IsMatch(p_SrcString, "[\xAC00-\xD7A3]+"))
                    
//当截取的起始位置超出字段串长度时
                    
if 
(p_StartIndex >= p_SrcString.Length)
                        
return 
""
;
                    
else
                        
return 
p_SrcString.Substring(p_StartIndex,
                                                       
((p_Length + p_StartIndex) > p_SrcString.Length) ? (p_SrcString.Length - p_StartIndex) : p_Length);
                
}
            
}
 
            
if 
(p_Length >= 0)
            
{
                
byte
[] bsSrcString = Encoding.Default.GetBytes(p_SrcString);
 
                
//当字符串长度大于起始位置
                
if 
(bsSrcString.Length > p_StartIndex)
                
{
                    
int 
p_EndIndex = bsSrcString.Length;
 
                    
//当要截取的长度在字符串的有效长度范围内
                    
if 
(bsSrcString.Length > (p_StartIndex + p_Length))
                    
{
                        
p_EndIndex = p_Length + p_StartIndex;
                    
}
                    
else
                    
{   
//当不在有效范围内时,只取到字符串的结尾
 
                        
p_Length = bsSrcString.Length - p_StartIndex;
                        
p_TailString = 
""
;
                    
}
 
                    
int 
nRealLength = p_Length;
                    
int
[] anResultFlag = 
new 
int
[p_Length];
                    
byte
[] bsResult = 
null
;
 
                    
int 
nFlag = 0;
                    
for 
(
int 
i = p_StartIndex; i < p_EndIndex; i++)
                    
{
                        
if 
(bsSrcString[i] > 127)
                        
{
                            
nFlag++;
                            
if 
(nFlag == 3)
                                
nFlag = 1;
                        
}
                        
else
                            
nFlag = 0;
 
                        
anResultFlag[i] = nFlag;
                    
}
 
                    
if 
((bsSrcString[p_EndIndex - 1] > 127) && (anResultFlag[p_Length - 1] == 1))
                        
nRealLength = p_Length + 1;
 
                    
bsResult = 
new 
byte
[nRealLength];
 
                    
Array.Copy(bsSrcString, p_StartIndex, bsResult, 0, nRealLength);
 
                    
myResult = Encoding.Default.GetString(bsResult);
                    
myResult = myResult + p_TailString;
                
}
            
}
 
            
return 
myResult;
        
}
 
        
/// <summary>
        
/// 获取Email HostName 例 liyangfd@gmail.com   获取出来时@gmail.com
        
/// </summary>
        
/// <param name="strEmail"></param>
        
/// <returns></returns>
        
public 
static 
string 
GetEmailHostName(
string 
strEmail)
        
{
            
if 
(strEmail.IndexOf(
"@"
) < 0)
            
{
                
return 
""
;
            
}
            
return 
strEmail.Substring(strEmail.LastIndexOf(
"@"
)).ToLower();
        
}
 
        
/// <summary>
        
/// 返回URL中结尾的文件名
        
/// </summary>       
        
public 
static 
string 
GetFilename(
string 
url)
        
{
            
if 
(url == 
null
)
            
{
                
return 
""
;
            
}
            
string
[] strs1 = url.Split(
new 
char
[] { 
'/' 
});
            
return 
strs1[strs1.Length - 1].Split(
new 
char
[] { 
'?' 
})[0];
        
}
 
 
        
/// <summary>
        
/// 根据阿拉伯数字返回月份的名称(可更改为某种语言)
        
/// </summary>   
        
public 
static 
string
[] Monthes
        
{
            
get
            
{
                
return 
new 
string
[] { 
"January"
"February"
"March"
"April"
"May"
"June"
"July"
"August"
"September"
"October"
"November"
"December" 
};
            
}
        
}
 
//判断部分
    
public 
class 
GF_IsOk
    
{
        
/// <summary>
        
/// 判读是否是IP地址
        
/// </summary>
        
/// <param name="in_str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsIPStr(
string  
in_str)
        
{
            
IPAddress ip;
            
return 
IPAddress.TryParse(in_str, 
out 
ip);
        
}
 
        
/// <summary>
        
/// 判断是否是数字
        
/// </summary>
        
/// <param name="strNumber"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsNumber(
string 
strNumber)
        
{
 
            
Regex objNotNumberPattern = 
new 
Regex(
"[^0-9.-]"
);
            
Regex objTwoDotPattern = 
new 
Regex(
"[0-9]*[.][0-9]*[.][0-9]*"
);
            
Regex objTwoMinusPattern = 
new 
Regex(
"[0-9]*[-][0-9]*[-][0-9]*"
);
            
String strValidRealPattern = 
"^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$"
;
            
String strValidIntegerPattern = 
"^([-]|[0-9])[0-9]*$"
;
            
Regex objNumberPattern = 
new 
Regex(
"(" 
+ strValidRealPattern + 
")|(" 
+ strValidIntegerPattern + 
")"
);
            
return 
!objNotNumberPattern.IsMatch(strNumber) &&
                   
!objTwoDotPattern.IsMatch(strNumber) &&
                   
!objTwoMinusPattern.IsMatch(strNumber) &&
                   
objNumberPattern.IsMatch(strNumber);
        
}
        
        
/// <summary>
        
///  判断是否是日期字符串
        
/// </summary>
        
/// <param name="in_str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsDateStr_yyyymmdd(
string 
in_str)
        
{
            
if 
(in_str == 
""
return 
true
;
            
if 
(in_str.Length != 8) 
return 
false
;
            
return 
IsDateStr(in_str);
        
}
 
        
/// <summary>
        
/// 判断是否是日期字符串
        
/// </summary>
        
/// <param name="in_str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsDateStr(
string 
in_str)
        
{
            
if 
(in_str == 
""
return 
true
;
            
if 
(in_str.Length == 8)
                
in_str = in_str.Substring(0, 4) + 
"-" 
+ in_str.Substring(4, 2) + 
"-" 
+ in_str.Substring(6, 2);
            
DateTime dtDate;
            
bool 
bValid = 
true
;
            
try
            
{
                
dtDate = DateTime.Parse(in_str);
            
}
            
catch 
(FormatException)
            
{
                
// 如果解析方法失败则表示不是日期性数据
                
bValid = 
false
;
            
}
            
return 
bValid;
        
}
 
        
/// <summary>
        
/// 判断字符串中是否包含汉字,有返回true 否则为false
        
/// </summary>
        
/// <param name="str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsExistHanZi(
string 
str)
        
{
            
Regex reg = 
new 
Regex(
@"[\u4e00-\u9fa5]"
);
//正则表达式
            
if 
(reg.IsMatch(str))
            
{
                
return 
true
;
            
}
            
else
            
{
                
return 
false
;
            
}
        
}
 
 
        
/// <summary>
        
/// 字段串是否为Null或为""(空)
        
/// </summary>
        
/// <param name="str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsStrNullOrEmpty(
string 
str)
        
{
            
if 
(str == 
null 
|| str.Trim() == 
string
.Empty)
                
return 
true
;
 
            
return 
false
;
        
}
 
        
/// <summary>
        
/// 返回文件是否存在
        
/// </summary>
        
/// <param name="filename">文件名</param>
        
/// <returns>是否存在</returns>
        
public 
static 
bool 
IsFileExists(
string 
filename)
        
{
            
return 
System.IO.File.Exists(filename);
        
}
 
 
        
/// <summary>
        
/// 检测是否符合email格式
        
/// </summary>
        
/// <param name="strEmail">要判断的email字符串</param>
        
/// <returns>判断结果</returns>
        
public 
static 
bool 
IsValidEmail(
string 
strEmail)
        
{
            
return 
Regex.IsMatch(strEmail, 
@"^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]"
);
        
}
 
        
public 
static 
bool 
IsValidDoEmail(
string 
strEmail)
        
{
            
return 
Regex.IsMatch(strEmail, 
@"^@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
);
        
}
        
/// <summary>
        
/// 检测是否是正确的Url
        
/// </summary>
        
/// <param name="strUrl">要验证的Url</param>
        
/// <returns>判断结果</returns>
        
public 
static 
bool 
IsURL(
string 
strUrl)
        
{
            
return 
Regex.IsMatch(strUrl, 
@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$"
);
        
}
 
        
/// <summary>
        
/// 判断是否为base64字符串
        
/// </summary>
        
/// <param name="str"></param>
        
/// <returns></returns>
        
public 
static 
bool 
IsBase64String(
string 
str)
        
{
            
//A-Z, a-z, 0-9, +, /, =
            
return 
Regex.IsMatch(str, 
@"[A-Za-z0-9\+\/\=]"
);
        
}
 
        
/// <summary>
        
/// 检测是否有Sql危险字符
        
/// </summary>
        
/// <param name="str">要判断字符串</param>
        
/// <returns>判断结果</returns>
        
public 
static 
bool 
IsSafeSqlString(
string 
str)
        
{
            
return 
!Regex.IsMatch(str, 
@"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']"
);
        
}  
    
}
 
 
 
/// <summary>
        
/// 获得伪静态页码显示链接
        
/// </summary>
        
/// <param name="curPage">当前页数</param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetStaticPageNumbers(
int 
curPage, 
int 
countPage, 
string 
url, 
string 
expname, 
int 
extendPage)
        
{
            
return 
GetStaticPageNumbers(curPage, countPage, url, expname, extendPage, 0);
        
}
 
 
        
/// <summary>
        
/// 获得伪静态页码显示链接
        
/// </summary>
        
/// <param name="curPage">当前页数</param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <param name="forumrewrite">当前版块是否使用URL重写</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetStaticPageNumbers(
int 
curPage, 
int 
countPage, 
string 
url, 
string 
expname, 
int 
extendPage, 
int 
forumrewrite)
        
{
            
int 
startPage = 1;
            
int 
endPage = 1;
 
            
string 
t1 = 
"<a href=\"" 
+ url + 
"-1" 
+ expname + 
"\">&laquo;</a>"
;
            
string 
t2 = 
"<a href=\"" 
+ url + 
"-" 
+ countPage + expname + 
"\">&raquo;</a>"
;
 
            
if 
(forumrewrite == 1)
            
{
                
t1 = 
"<a href=\"" 
+ url + 
"/1/list" 
+ expname + 
"\">&laquo;</a>"
;
                
t2 = 
"<a href=\"" 
+ url + 
"/" 
+ countPage + 
"/list" 
+ expname + 
"\">&raquo;</a>"
;
            
}
 
            
if 
(forumrewrite == 2)
            
{
                
t1 = 
"<a href=\"" 
+ url + 
"/\">&laquo;</a>"
;
                
t2 = 
"<a href=\"" 
+ url + 
"/" 
+ countPage + 
"/\">&raquo;</a>"
;
            
}
 
            
if 
(countPage < 1) countPage = 1;
            
if 
(extendPage < 3) extendPage = 2;
 
            
if 
(countPage > extendPage)
            
{
                
if 
(curPage - (extendPage / 2) > 0)
                
{
                    
if 
(curPage + (extendPage / 2) < countPage)
                    
{
                        
startPage = curPage - (extendPage / 2);
                        
endPage = startPage + extendPage - 1;
                    
}
                    
else
                    
{
                        
endPage = countPage;
                        
startPage = endPage - extendPage + 1;
                        
t2 = 
""
;
                    
}
                
}
                
else
                
{
                    
endPage = extendPage;
                    
t1 = 
""
;
                
}
            
}
            
else
            
{
                
startPage = 1;
                
endPage = countPage;
                
t1 = 
""
;
                
t2 = 
""
;
            
}
 
            
StringBuilder s = 
new 
StringBuilder(
""
);
 
            
s.Append(t1);
            
for 
(
int 
i = startPage; i <= endPage; i++)
            
{
                
if 
(i == curPage)
                
{
                    
s.Append(
"<span>"
);
                    
s.Append(i);
                    
s.Append(
"</span>"
);
                
}
                
else
                
{
                    
s.Append(
"<a href=\""
);
                    
if 
(forumrewrite == 1)
                    
{
                        
s.Append(url);
                        
if 
(i != 1)
                        
{
                            
s.Append(
"/"
);
                            
s.Append(i);
                        
}
                        
s.Append(
"/list"
);
                        
s.Append(expname);
                    
}
                    
else 
if 
(forumrewrite == 2)
                    
{
                        
s.Append(url);
                        
s.Append(
"/"
);
                        
if 
(i != 1)
                        
{
                            
s.Append(i);
                            
s.Append(
"/"
);
                        
}
                    
}
                    
else
                    
{
                        
s.Append(url);
                        
if 
(i != 1)
                        
{
                            
s.Append(
"-"
);
                            
s.Append(i);
                        
}
                        
s.Append(expname);
                    
}
                    
s.Append(
"\">"
);
                    
s.Append(i);
                    
s.Append(
"</a>"
);
                
}
            
}
            
s.Append(t2);
 
            
return 
s.ToString();
        
}
 
 
        
/// <summary>
        
/// 获得帖子的伪静态页码显示链接
        
/// </summary>
        
/// <param name="expname"></param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetPostPageNumbers(
int 
countPage, 
string 
url, 
string 
expname, 
int 
extendPage)
        
{
            
int 
startPage = 1;
            
int 
endPage = 1;
            
int 
curPage = 1;
 
            
string 
t1 = 
"<a href=\"" 
+ url + 
"-1" 
+ expname + 
"\">&laquo;</a>"
;
            
string 
t2 = 
"<a href=\"" 
+ url + 
"-" 
+ countPage + expname + 
"\">&raquo;</a>"
;
 
            
if 
(countPage < 1) countPage = 1;
            
if 
(extendPage < 3) extendPage = 2;
 
            
if 
(countPage > extendPage)
            
{
                
if 
(curPage - (extendPage / 2) > 0)
                
{
                    
if 
(curPage + (extendPage / 2) < countPage)
                    
{
                        
startPage = curPage - (extendPage / 2);
                        
endPage = startPage + extendPage - 1;
                    
}
                    
else
                    
{
                        
endPage = countPage;
                        
startPage = endPage - extendPage + 1;
                        
t2 = 
""
;
                    
}
                
}
                
else
                
{
                    
endPage = extendPage;
                    
t1 = 
""
;
                
}
            
}
            
else
            
{
                
startPage = 1;
                
endPage = countPage;
                
t1 = 
""
;
                
t2 = 
""
;
            
}
 
            
StringBuilder s = 
new 
StringBuilder(
""
);
 
            
s.Append(t1);
            
for 
(
int 
i = startPage; i <= endPage; i++)
            
{
                
s.Append(
"<a href=\""
);
                
s.Append(url);
                
s.Append(
"-"
);
                
s.Append(i);
                
s.Append(expname);
                
s.Append(
"\">"
);
                
s.Append(i);
                
s.Append(
"</a>"
);
            
}
            
s.Append(t2);
 
            
return 
s.ToString();
        
}
 
 
/// <summary>
        
/// 获得页码显示链接
        
/// </summary>
        
/// <param name="curPage">当前页数</param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetPageNumbers(
int 
curPage, 
int 
countPage, 
string 
url, 
int 
extendPage)
        
{
            
return 
GetPageNumbers(curPage, countPage, url, extendPage, 
"page"
);
        
}
 
        
/// <summary>
        
/// 获得页码显示链接
        
/// </summary>
        
/// <param name="curPage">当前页数</param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <param name="pagetag">页码标记</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetPageNumbers(
int 
curPage, 
int 
countPage, 
string 
url, 
int 
extendPage, 
string 
pagetag)
        
{
            
return 
GetPageNumbers(curPage, countPage, url, extendPage, pagetag, 
null
);
        
}
 
        
/// <summary>
        
/// 获得页码显示链接
        
/// </summary>
        
/// <param name="curPage">当前页数</param>
        
/// <param name="countPage">总页数</param>
        
/// <param name="url">超级链接地址</param>
        
/// <param name="extendPage">周边页码显示个数上限</param>
        
/// <param name="pagetag">页码标记</param>
        
/// <param name="anchor">锚点</param>
        
/// <returns>页码html</returns>
        
public 
static 
string 
GetPageNumbers(
int 
curPage, 
int 
countPage, 
string 
url, 
int 
extendPage, 
string 
pagetag, 
string 
anchor)
        
{
            
if 
(pagetag == 
""
)
                
pagetag = 
"page"
;
            
int 
startPage = 1;
            
int 
endPage = 1;
 
            
if 
(url.IndexOf(
"?"
) > 0)
                
url = url + 
"&"
;
            
else
                
url = url + 
"?"
;
 
            
string 
t1 = 
"<a href=\"" 
+ url + 
"&" 
+ pagetag + 
"=1"
;
            
string 
t2 = 
"<a href=\"" 
+ url + 
"&" 
+ pagetag + 
"=" 
+ countPage;
            
if 
(anchor != 
null
)
            
{
                
t1 += anchor;
                
t2 += anchor;
            
}
            
t1 += 
"\">&laquo;</a>"
;
            
t2 += 
"\">&raquo;</a>"
;
 
            
if 
(countPage < 1)
                
countPage = 1;
            
if 
(extendPage < 3)
                
extendPage = 2;
 
            
if 
(countPage > extendPage)
            
{
                
if 
(curPage - (extendPage / 2) > 0)
                
{
                    
if 
(curPage + (extendPage / 2) < countPage)
                    
{
                        
startPage = curPage - (extendPage / 2);
                        
endPage = startPage + extendPage - 1;
                    
}
                    
else
                    
{
                        
endPage = countPage;
                        
startPage = endPage - extendPage + 1;
                        
t2 = 
""
;
                    
}
                
}
                
else
                
{
                    
endPage = extendPage;
                    
t1 = 
""
;
                
}
            
}
            
else
            
{
                
startPage = 1;
                
endPage = countPage;
                
t1 = 
""
;
                
t2 = 
""
;
            
}
 
            
StringBuilder s = 
new 
StringBuilder(
""
);
 
            
s.Append(t1);
            
for 
(
int 
i = startPage; i <= endPage; i++)
            
{
                
if 
(i == curPage)
                
{
                    
s.Append(
"<span>"
);
                    
s.Append(i);
                    
s.Append(
"</span>"
);
                
}
                
else
                
{
                    
s.Append(
"<a href=\""
);
                    
s.Append(url);
                    
s.Append(pagetag);
                    
s.Append(
"="
);
                    
s.Append(i);
                    
if 
(anchor != 
null
)
                    
{
                        
s.Append(anchor);
                    
}
                    
s.Append(
"\">"
);
                    
s.Append(i);
                    
s.Append(
"</a>"
);
                
}
            
}
            
s.Append(t2);
 
            
return 
s.ToString();
        
}
 
        
/// <summary>
        
/// 判断文件流是否为UTF8字符集
        
/// </summary>
        
/// <param name="sbInputStream">文件流</param>
        
/// <returns>判断结果</returns>
        
private 
static 
bool 
IsUTF8(FileStream sbInputStream)
        
{
            
int 
i;
            
byte 
cOctets;  
// octets to go in this UTF-8 encoded character 
            
byte 
chr;
            
bool 
bAllAscii = 
true
;
            
long 
iLen = sbInputStream.Length;
 
            
cOctets = 0;
            
for 
(i = 0; i < iLen; i++)
            
{
                
chr = (
byte
)sbInputStream.ReadByte();
 
                
if 
((chr & 0x80) != 0) bAllAscii = 
false
;
 
                
if 
(cOctets == 0)
                
{
                    
if 
(chr >= 0x80)
                    
{
                        
do
                        
{
                            
chr <<= 1;
                            
cOctets++;
                        
}
                        
while 
((chr & 0x80) != 0);
 
                        
cOctets--;
                        
if 
(cOctets == 0)
                            
return 
false
;
                    
}
                
}
                
else
                
{
                    
if 
((chr & 0xC0) != 0x80)
                        
return 
false
;
 
                    
cOctets--;
                
}
            
}
 
            
if 
(cOctets > 0)
                
return 
false
;
 
            
if 
(bAllAscii)
                
return 
false
;
 
            
return 
true
;
        
}
 
 
 

转载于:https://www.cnblogs.com/liufei88866/p/3478358.html

你可能感兴趣的文章
部署core
查看>>
mysql 时间设置
查看>>
如何在 Xcode 中修改应用的名字
查看>>
有关交换机——熟悉原理是必须的【转载】
查看>>
ACM(数学问题)——UVa202:输入整数a和b(0≤a≤3000,1≤b≤3000),输出a/b的循环小数表示以及循环节长度。...
查看>>
【转】Android 读取doc文件
查看>>
js 数据绑定
查看>>
jsp的C标签一般使用方法以及js接收servlet中的对象及对象数字
查看>>
H5 简介
查看>>
window.frameElement的使用
查看>>
nl命令
查看>>
如何使用jQuery $.post() 方法实现前后台数据传递
查看>>
Using Flash Builder with Flash Professional
查看>>
jsp/post中文乱码问题
查看>>
C# 插入或删除word分页符
查看>>
数据库数据的查询----连接查询
查看>>
找不到可安装的ISAM ,asp.net读取数据丢失,解决的一列里有字符与数字的
查看>>
Java学习笔记三(对象的基本思想一)
查看>>
Java程序(文件操作)
查看>>
KMP算法 最小循环节 最大重复次数
查看>>