using System;
using System.Collections.Generic;
using System.Text;
namespace PubClass
{
public class someMethod
{
public bool IsInt(string s) //是否为整型
{
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\A[0-9]+\Z");
bool result;
result = reg.IsMatch(s);
return result;
}
public bool isNum(string s) //判断是否为整型数字
{
for (int index = 0; index < s.Length; index++)
{
if (48 > (int)s[index] || (int)s[index] > 57)
return false;
}
return true;
}
public void sendmail(string femail, string fname, string phone, string unit, string semail, string sname, string content, string title)
{
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["MailServer"];
MailMessage mail = new MailMessage();
mail.BodyFormat = MailFormat.Html;
mail.To = semail;
mail.From = femail;
mail.Subject = title;
mail.Body = sname + "您好!<br><br>" + content +
"<br> " + unit + " " + fname +
"<br> " + phone + "<br>" +
" " + DateTime.Now.Date.ToShortDateString() + "<br>";
SmtpMail.Send(mail);
}
public string CutString(string inputString, int len)//截取指定长度字符串
{
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
string tempString = "";
char[] s = inputString.ToCharArray();
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] > 127)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
try
{
tempString += inputString.Substring(i, 1);
}
catch
{
break;
}
if (tempLen > len)
break;
}
//如果截过则加上半个省略号
if (s.Length > len)
tempString += "…";
return tempString;
}
public bool intN(string inputString, int leng)//判断输入串是否为int类型
{
try
{
int i = int.Parse(inputString);
if (i.ToString().Length <= leng && i.ToString().Length >= 0)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
public bool CountByte(string inputString, int len)//判断字节数是否超过指定长度
{
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
char[] s = inputString.ToCharArray();
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] > 127)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
}
if (tempLen <= len)
return true;
else
return false;
}
}
}