CommonHelper 公共类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace WebHelper
{
    public static class CommonHelper
    {
        #region 1.0 根据相对路径 读取 文件的内容字符串 +string GetFileContent(string filePath)
        /// <summary>
        /// 根据相对路径 读取 文件的内容字符串
        /// </summary>
        /// <param name="filePath">文件的相对路径</param>
        /// <returns></returns>
        public static string GetFileContent(string filePath)
        {
            //根据相对路径(虚拟路径) 获取 绝对路径(物理路径)
            string phyPath = HttpContext.Current.Server.MapPath(filePath);
            //读取文件内容
            string strContent = System.IO.File.ReadAllText(phyPath);
            //返回文件内容
            return strContent;
        } 
        #endregion

        #region 2.0 直接输出 js消息 并完成跳转 +WriteJs(string msg, string url)
        /// <summary>
        /// 直接输出 js 消息
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteJs(string msg)
        {
            HttpContext.Current.Response.Write("<script>alert('" + msg + "');</script>");
        }
        /// <summary>
        /// 直接输出 js消息 并完成跳转
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void WriteJs(string msg, string url)
        {
            HttpContext.Current.Response.Write("<script>alert('" + msg + "');window.location='" + url + "';</script>");
        } 
        #endregion

        #region 3.0 使用正则表达式验证 参数 是否为数值 +bool IsNum(string strNumber)
        /// <summary>
        /// 使用正则表达式验证 参数 是否为数值
        /// </summary>
        /// <param name="strNumber"></param>
        /// <returns></returns>
        public static bool IsNum(string strNumber)
        {
            Regex reg = new Regex(@"^\d+$");//数值正则表达式(一个或多个数字)
            return reg.IsMatch(strNumber);
        } 
        #endregion
    }
}

 

转载于:https://www.cnblogs.com/hehehehehe/p/5100764.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值