基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
/******************************
|
||||
* 说明:字符串扩展
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2018-05-28
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Lskj.Util
|
||||
{
|
||||
public static class StringExtend
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:字符串转换为DataTable</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-05-28 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="stringData">The string data.</param>
|
||||
/// <param name="columns">The columns.</param>
|
||||
/// <returns>DataTable.</returns>
|
||||
public static DataTable ToNewDataTable(this string stringData,string columns)
|
||||
{
|
||||
DataTable dtTable = new DataTable();
|
||||
stringData = stringData.Replace(" ", "").Replace(",,", ",").Trim(',');
|
||||
string[] confirmOper = stringData.Split(',');
|
||||
for (int i = 0; i < confirmOper.Length; i++)
|
||||
{
|
||||
DataRow row = dtTable.NewRow();
|
||||
row[columns] = confirmOper[i];
|
||||
dtTable.Rows.Add(row);
|
||||
}
|
||||
return dtTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-10-23 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="s">The s.</param>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public static string ToStr(this object s, string format = "")
|
||||
{
|
||||
string result = string.Empty;
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(format))
|
||||
{
|
||||
result = s.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = string.Format("{0:" + format + "}", s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:{key}字符串替换</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-05-28 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="ignoreCase">是否忽略大小写</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string Replace(this string str, string key, string value, bool ignoreCase)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return str;
|
||||
|
||||
return Regex.IsMatch(str, key, RegexOptions.IgnoreCase) ?
|
||||
System.Text.RegularExpressions.Regex.Replace(str, key, value, ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None)
|
||||
: str;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期: </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
public static bool IsChinese(this string text)
|
||||
{
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if ((int)text[i] > 127)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user