在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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 c 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 例 [email protected] 获取出来时@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>
全部评论
专题导读
热门推荐
热门话题
阅读排行榜
|
请发表评论