C# Class System.StringHelper

字符串操作类 1、GetStrArray(string str, char speater, bool toLower) 把字符串按照分隔符转换成 List 2、GetStrArray(string str) 把字符串转 按照, 分割 换为数据 3、GetArrayStr(List list, string speater) 把 List 按照分隔符组装成 string 4、GetArrayStr(List list) 得到数组列表以逗号分隔的字符串 5、GetArrayValueStr(Dictionary list)得到数组列表以逗号分隔的字符串 6、DelLastComma(string str)删除最后结尾的一个逗号 7、DelLastChar(string str, string strchar)删除最后结尾的指定字符后的字符 8、ToSBC(string input)转全角的函数(SBC case) 9、ToDBC(string input)转半角的函数(SBC case) 10、GetSubStringList(string o_str, char sepeater)把字符串按照指定分隔符装成 List 去除重复 11、GetCleanStyle(string StrList, string SplitString)将字符串样式转换为纯字符串 12、GetNewStyle(string StrList, string NewStyle, string SplitString, out string Error)将字符串转换为新样式 13、SplitMulti(string str, string splitstr)分割字符串 14、SqlSafeString(string String, bool IsDel)
Show file Open project: stoneson/NewLifeX Class Usage Examples

Public Methods

Method Description
Cut ( String str, Int32 maxLength, String pad = null ) : String

根据最大长度截取字符串,并允许以指定空白填充末尾

CutEnd ( String str ) : String

从当前字符串结尾移除另一字符串以及之后的部分

CutStart ( String str ) : String

从当前字符串开头移除另一字符串以及之前的部分

EndsWithIgnoreCase ( String value ) : System.Boolean

忽略大小写的字符串结束比较,判断是否以任意一个待比较字符串结束

EnsureEnd ( String str, String end ) : String

确保字符串以指定的另一字符串结束,不区分大小写

EnsureStart ( String str, String start ) : String

确保字符串以指定的另一字符串开始,不区分大小写

EqualIgnoreCase ( String value ) : System.Boolean

忽略大小写的字符串相等比较,判断是否以任意一个待比较字符串相等

F ( String value ) : String

格式化字符串。特别支持无格式化字符串的时间参数

GetBytes ( String value, System.Encoding encoding = null ) : Byte[]

字符串转数组

IsNullOrEmpty ( String value ) : Boolean

指示指定的字符串是 null 还是 String.Empty 字符串

IsNullOrWhiteSpace ( String value ) : Boolean

是否空或者空白字符串

Join ( IEnumerable value, String separator = "," ) : String

把一个列表组合成为一个字符串,默认逗号分隔

Join ( IEnumerable value, String separator, Func func ) : String

把一个列表组合成为一个字符串,默认逗号分隔

LCS ( IEnumerable list, String keys, Func keySelector ) : Double>>.IEnumerable

根据列表项成员计算距离

LCSDistance ( String word, Array keys ) : Int32

最长公共子序列问题是寻找两个或多个已知数列最长的子序列。 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。 The longest common subsequence (LCS) problem is to find the longest subsequence common to all sequences in a set of sequences (often just two). Note that subsequence is different from a substring, see substring vs. subsequence. It is a classic computer science problem, the basis of diff (a file comparison program that outputs the differences between two files), and has applications in bioinformatics.

算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html

LCSSearch ( String key, Array words ) : String[]

最长公共子序列搜索,从词组中找到最接近关键字的若干匹配项

算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html

LCSSearch ( IEnumerable list, String keys, Func keySelector, Int32 count = -1 ) : IEnumerable

在列表项中进行模糊搜索

LevenshteinDistance ( String str1, String str2 ) : Int32

编辑距离

又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。 许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。 算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html

LevenshteinSearch ( String key, Array words ) : String[]

编辑距离搜索,从词组中找到最接近关键字的若干匹配项

算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html

Match ( String str, String key, Int32 maxError ) : Int32>.KeyValuePair

模糊匹配

Match ( IEnumerable list, String keys, Func keySelector ) : Double>>.IEnumerable

模糊匹配

Match ( IEnumerable list, String keys, Func keySelector, Int32 count, Double confidence = 0.5 ) : IEnumerable

模糊匹配

Run ( String cmd, String arguments = null, Int32 msWait, Action output = null, Action onExit = null ) : Int32

以隐藏窗口执行命令行

Separate ( StringBuilder sb, String separator ) : StringBuilder

追加分隔符字符串,忽略开头,常用于拼接

Speak ( String value ) : void

调用语音引擎说出指定话

SpeakAsync ( String value ) : void

异步调用语音引擎说出指定话。可能导致后来的调用打断前面的语音

SpeechTip ( String value ) : void

语音提示操作

Split ( String value ) : String[]

拆分字符串,过滤空格,无效时返回空数组

SplitAsDictionary ( String value, String nameValueSeparator = "=", String separator = ";", Boolean trimQuotation = false ) : String>.IDictionary

拆分字符串成为不区分大小写的可空名值字典。逗号分组,等号分隔

SplitAsInt ( String value ) : Int32[]

拆分字符串成为整型数组,默认逗号分号分隔,无效时返回空数组

过滤空格、过滤无效、不过滤重复

StartsWithIgnoreCase ( String value ) : Boolean

忽略大小写的字符串开始比较,判断是否以任意一个待比较字符串开始

Substring ( String str, String after, String before = null, Int32 startIndex, Array positions = null ) : String

从字符串中检索子字符串,在指定头部字符串之后,指定尾部字符串之前

常用于截取xml某一个元素等操作

TrimEnd ( String str ) : String

从当前字符串结尾移除另一字符串,不区分大小写,循环多次匹配后缀

TrimStart ( String str ) : String

从当前字符串开头移除另一字符串,不区分大小写,循环多次匹配前缀

Private Methods

Method Description
Init ( ) : void
SplitAsDictionary ( String value, String nameValueSeparator = "=" ) : String>.IDictionary

Method Details

Cut() public static method

根据最大长度截取字符串,并允许以指定空白填充末尾
public static Cut ( String str, Int32 maxLength, String pad = null ) : String
str String 字符串
maxLength Int32 截取后字符串的最大允许长度,包含后面填充
pad String 需要填充在后面的字符串,比如几个圆点
return String

CutEnd() public static method

从当前字符串结尾移除另一字符串以及之后的部分
public static CutEnd ( String str ) : String
str String 当前字符串
return String

CutStart() public static method

从当前字符串开头移除另一字符串以及之前的部分
public static CutStart ( String str ) : String
str String 当前字符串
return String

EndsWithIgnoreCase() public static method

忽略大小写的字符串结束比较,判断是否以任意一个待比较字符串结束
public static EndsWithIgnoreCase ( String value ) : System.Boolean
value String 字符串
return System.Boolean

EnsureEnd() public static method

确保字符串以指定的另一字符串结束,不区分大小写
public static EnsureEnd ( String str, String end ) : String
str String 字符串
end String
return String

EnsureStart() public static method

确保字符串以指定的另一字符串开始,不区分大小写
public static EnsureStart ( String str, String start ) : String
str String 字符串
start String
return String

EqualIgnoreCase() public static method

忽略大小写的字符串相等比较,判断是否以任意一个待比较字符串相等
public static EqualIgnoreCase ( String value ) : System.Boolean
value String 字符串
return System.Boolean

F() public static method

格式化字符串。特别支持无格式化字符串的时间参数
public static F ( String value ) : String
value String 格式字符串
return String

GetBytes() public static method

字符串转数组
public static GetBytes ( String value, System.Encoding encoding = null ) : Byte[]
value String 字符串
encoding System.Encoding 编码,默认utf-8无BOM
return Byte[]

IsNullOrEmpty() public static method

指示指定的字符串是 null 还是 String.Empty 字符串
public static IsNullOrEmpty ( String value ) : Boolean
value String 字符串
return Boolean

IsNullOrWhiteSpace() public static method

是否空或者空白字符串
public static IsNullOrWhiteSpace ( String value ) : Boolean
value String 字符串
return Boolean

Join() public static method

把一个列表组合成为一个字符串,默认逗号分隔
public static Join ( IEnumerable value, String separator = "," ) : String
value IEnumerable
separator String 组合分隔符,默认逗号
return String

Join() public static method

把一个列表组合成为一个字符串,默认逗号分隔
public static Join ( IEnumerable value, String separator, Func func ) : String
value IEnumerable
separator String 组合分隔符,默认逗号
func Func 把对象转为字符串的委托
return String

LCS() public static method

根据列表项成员计算距离
public static LCS ( IEnumerable list, String keys, Func keySelector ) : Double>>.IEnumerable
list IEnumerable
keys String
keySelector Func
return Double>>.IEnumerable

LCSDistance() public static method

最长公共子序列问题是寻找两个或多个已知数列最长的子序列。 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。 The longest common subsequence (LCS) problem is to find the longest subsequence common to all sequences in a set of sequences (often just two). Note that subsequence is different from a substring, see substring vs. subsequence. It is a classic computer science problem, the basis of diff (a file comparison program that outputs the differences between two files), and has applications in bioinformatics.
算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html
public static LCSDistance ( String word, Array keys ) : Int32
word String
keys Array 多个关键字。长度必须大于0,必须按照字符串长度升序排列。
return Int32

LCSSearch() public static method

最长公共子序列搜索,从词组中找到最接近关键字的若干匹配项
算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html
public static LCSSearch ( String key, Array words ) : String[]
key String
words Array
return String[]

LCSSearch() public static method

在列表项中进行模糊搜索
public static LCSSearch ( IEnumerable list, String keys, Func keySelector, Int32 count = -1 ) : IEnumerable
list IEnumerable
keys String
keySelector Func
count Int32
return IEnumerable

LevenshteinDistance() public static method

编辑距离
又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。 许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。 算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html
public static LevenshteinDistance ( String str1, String str2 ) : Int32
str1 String
str2 String
return Int32

LevenshteinSearch() public static method

编辑距离搜索,从词组中找到最接近关键字的若干匹配项
算法代码由@Aimeast 独立完成。http://www.cnblogs.com/Aimeast/archive/2011/09/05/2167844.html
public static LevenshteinSearch ( String key, Array words ) : String[]
key String 关键字
words Array 词组
return String[]

Match() public static method

模糊匹配
public static Match ( String str, String key, Int32 maxError ) : Int32>.KeyValuePair
str String
key String
maxError Int32
return Int32>.KeyValuePair

Match() public static method

模糊匹配
public static Match ( IEnumerable list, String keys, Func keySelector ) : Double>>.IEnumerable
list IEnumerable
keys String
keySelector Func
return Double>>.IEnumerable

Match() public static method

模糊匹配
public static Match ( IEnumerable list, String keys, Func keySelector, Int32 count, Double confidence = 0.5 ) : IEnumerable
list IEnumerable 列表项
keys String 关键字
keySelector Func 匹配字符串选择
count Int32 获取个数
confidence Double 权重阀值
return IEnumerable

Run() public static method

以隐藏窗口执行命令行
public static Run ( String cmd, String arguments = null, Int32 msWait, Action output = null, Action onExit = null ) : Int32
cmd String 文件名
arguments String 命令参数
msWait Int32 等待毫秒数
output Action 进程输出内容。默认为空时输出到日志
onExit Action 进程退出时执行
return Int32

Separate() public static method

追加分隔符字符串,忽略开头,常用于拼接
public static Separate ( StringBuilder sb, String separator ) : StringBuilder
sb StringBuilder 字符串构造者
separator String 分隔符
return StringBuilder

Speak() public static method

调用语音引擎说出指定话
public static Speak ( String value ) : void
value String
return void

SpeakAsync() public static method

异步调用语音引擎说出指定话。可能导致后来的调用打断前面的语音
public static SpeakAsync ( String value ) : void
value String
return void

SpeechTip() public static method

语音提示操作
public static SpeechTip ( String value ) : void
value String
return void

Split() public static method

拆分字符串,过滤空格,无效时返回空数组
public static Split ( String value ) : String[]
value String 字符串
return String[]

SplitAsDictionary() public static method

拆分字符串成为不区分大小写的可空名值字典。逗号分组,等号分隔
public static SplitAsDictionary ( String value, String nameValueSeparator = "=", String separator = ";", Boolean trimQuotation = false ) : String>.IDictionary
value String 字符串
nameValueSeparator String 名值分隔符,默认等于号
separator String 分组分隔符,默认分号
trimQuotation Boolean 去掉括号
return String>.IDictionary

SplitAsInt() public static method

拆分字符串成为整型数组,默认逗号分号分隔,无效时返回空数组
过滤空格、过滤无效、不过滤重复
public static SplitAsInt ( String value ) : Int32[]
value String 字符串
return Int32[]

StartsWithIgnoreCase() public static method

忽略大小写的字符串开始比较,判断是否以任意一个待比较字符串开始
public static StartsWithIgnoreCase ( String value ) : Boolean
value String 字符串
return Boolean

Substring() public static method

从字符串中检索子字符串,在指定头部字符串之后,指定尾部字符串之前
常用于截取xml某一个元素等操作
public static Substring ( String str, String after, String before = null, Int32 startIndex, Array positions = null ) : String
str String 目标字符串
after String 头部字符串,在它之后
before String 尾部字符串,在它之前
startIndex Int32 搜索的开始位置
positions Array 位置数组,两个元素分别记录头尾位置
return String

TrimEnd() public static method

从当前字符串结尾移除另一字符串,不区分大小写,循环多次匹配后缀
public static TrimEnd ( String str ) : String
str String 当前字符串
return String

TrimStart() public static method

从当前字符串开头移除另一字符串,不区分大小写,循环多次匹配前缀
public static TrimStart ( String str ) : String
str String 当前字符串
return String