几个通用操作方法

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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + unit + "&nbsp;&nbsp;&nbsp;&nbsp;" + fname +
                "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + phone + "<br>" +
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 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;
        }
    }
   
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值