WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
 
namespace JiepeiWMS.Extends
{
    /// <summary>
    /// 数值扩展
    /// </summary>
    public static class ExtString
    {
        #region Sql转换
        /// <summary>
        /// 转换成SQL字符串
        /// </summary>
        /// <param name="Value">字符串</param>
        /// <returns>SQL字符串</returns>
        public static string _ToSqlStr(this string Value)
        {
            return Value.Replace("'", "''");
        }
        /// <summary>
        /// 转换成SQL Like条件查询字符串(非法字符会被过滤掉)
        /// </summary>
        /// <param name="Value">字符串</param>
        /// <returns>SQL Like条件查询字符串</returns>
        public static string _ToSqlLikeStr(this string Value)
        {
            var likestr = Value._ToSqlStr().Replace("[", "[[]").Replace("%", "[%]").Replace("_", "[_]");
            return likestr;
        }
        /// <summary>
        /// 转换成SQL字段名(非法字符会被过滤掉)
        /// </summary>
        /// <param name="Value">字符串</param>
        /// <returns>SQL字段名</returns>
        public static string _ToSqlFieldStr(this string Value)
        {
            return Regex.Replace(Value, @"[^\w,]+", "");
        }
        #endregion
 
    }
 
}