PS C:\> ("Pstips.net" | Get-Member Split).definition.Replace("), ", ")`n")
string[] Split(Params char[] separator)
string[] Split(char[] separator, int count)
string[] Split(char[] separator, System.StringSplitOptions options)
string[] Split(char[] separator, int count, System.StringSplitOptions options)
string[] Split(string[] separator, System.StringSplitOptions options)
string[] Split(string[] separator, int count, System.StringSplitOptions options)
之前说过反引号,类似高级语言中的转义符反斜杠。
PowerShell在处理文本时,可能会碰到多个分隔符,而Split方法调用只须一次即可。
PS C:\> "http://www.pstips.net".split(":./")
http
www
pstips
net
中间有空白,咋整,能移除吗,StringSplitOptions轻装上阵:
PS C:\> "http://www.pstips.net".split(":./",[StringSplitOptions]::RemoveEmptyEntries)
http
www
pstips
net
之前有一个小算法题,移除字符串中相邻的重复的空格。在不考虑效率的前提下,可以使用Split先分割,分割后再将得到的元素以指定分隔符拼接。但是拼接用到的Join方法,并不属于string对象,而属于String类。