VBScript Left 函數
Left 函數從字符串的左側返回指定數量的字符。
提示:請使用Len函數來確定字符串中的字符數量。
提示:請參閱Right函數。
語法
Left(string,length)
参数 | 描述 |
---|---|
string | 必需。从其中返回字符的字符串。 |
length | 必需。规定需返回多少字符。如果设置为 0,则返回空字符串("")。如果设置为大于或等于字符串的长度,则返回整个字符串。 |
實例
實例1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Left(txt,15))
</script>
txt="This is a beautiful day!"
document.write(Left(txt,15))
</script>
以上實例輸出結果:
This is a beaut
嘗試一下»
實例2
返回整個字符串:
<script type="text/vbscript">
txt="This is a beautiful day!"
x=Len(txt)
document.write(Left(txt,x))
</script>
txt="This is a beautiful day!"
x=Len(txt)
document.write(Left(txt,x))
</script>
以上實例輸出結果:
This is a beautiful day!
嘗試一下»
完整的VBScript參考手冊