$x="abcd"
;#方法一
;%exprlength$x
MsgBox(0,"我们来看Shell中求字符串长度的例子: ",StringLen($x))
;# 方法二
;%echo${#x}
MsgBox(0,"我们来看Shell中求字符串长度的例子: ",BinaryLen(StringToBinary(Eval("x"))))
;# 方法三
;%expr"$x":".*"
MsgBox(0,"我们来看Shell中求字符串长度的例子: ",StringSplit($x,"")[0])
;-----------------------------------------------------------------------------------
;PS C:\>"abcd"
$x=FileGetLongName("d:\abcd")
MsgBox(0,"调用字符串长度的属性就可以返回字符串长度",StringSplit($x,"")[2])
;abcd
;PS C:\>"abcd".length
MsgBox(0,"调用字符串长度的属性就可以返回字符串长度",StringLen(StringSplit($x,"")[2]))
;4
;--------------------------------------------------------------------------
$x="abcd"
;%exprindex$x"a"
MsgBox(0,"查找子串",StringInStr($x,"a"))
;1
;%exprindex$x"bc"
MsgBox(0,"查找子串",StringInStr($x,"bc"))
;2
;%exprindex$x"cd"
MsgBox(0,"查找子串",StringInStr($x,"cd"))
;3
;------------------------------------------------------------------------
$x=StringSplit("abcd","a")
MsgBox(0,"数组下标是从0开始计数的","1="&$x[0]&@CR&"2="&$x[1]&@CR&"3="&$x[2]&@CR&"共有"&UBound($x)&"个") ;为了让大家明白是什么回事,故添加此步!!
;PS C:\>$x="abcd"
;PS C:\>$x.IndexOf('a')
MsgBox(0,"数组下标是从0开始计数的",StringInStr($x[2],"a")) ;呵呵,结果是0,千万不要被结果迷惑哦!这里的0是表示失败的意思,而不是真正的0!!
;0
;PS C:\>$x.IndexOf('b')
MsgBox(0,"数组下标是从0开始计数的",StringInStr($x[2],"b"))
;1
;PS C:\>$x.IndexOf('bc')
MsgBox(0,"数组下标是从0开始计数的",StringInStr($x[2],"bc"))
;1
;PS C:\>$x.IndexOf('cd')
MsgBox(0,"数组下标是从0开始计数的",StringInStr($x[2],"cd"))
;2
;PS C:\>$x.IndexOf('ef')
MsgBox(0,"数组下标是从0开始计数的",StringInStr($x[2],"ef")) ;这里结果也是0,而不是-1 注意哦!为啥?上面已解释!
;-1
;-----------------------------------------------------------------
$x="abcd"
;# 方法一
;# expr <string> startpos length
;%exprsubstr"$x"1 3
MsgBox(0,"得到子字符串",StringMid($x,1,3))
;abc
;%exprsubstr"$x"1 5
MsgBox(0,"得到子字符串",StringMid($x,1,5))
;abcd
;%exprsubstr"$x"2 5
MsgBox(0,"得到子字符串",StringMid($x,2,3))
;bcd
;# 方法二
;# ${x:pos:lenght}
;%echo${x:1}
MsgBox(0,"得到子字符串",StringTrimLeft($x,1))
;bcd
;%echo${x:2}
MsgBox(0,"得到子字符串",StringTrimLeft($x,2))
;cd
;%echo${x:0}
MsgBox(0,"得到子字符串",StringTrimLeft($x,0))
;abcd
;%echo${x:0:2}
MsgBox(0,"得到子字符串",StringTrimRight($x,2))
;ab
;%pos=1
;%len=2
;%echo${x:$pos:$len}
MsgBox(0,"得到子字符串",StringTrimLeft(StringTrimLeft($x,1)&StringTrimRight($x,1),4))
;bc
;------来看看PowerShell的Substring方法吧 代码类同上面的组合,不再写了-------------