Visual Basic Left 函数
定义和用法
Left 函数可从字符串的左侧返回指定数目的字符。
提示:请使用 Len 函数 来确定字符串中的字符数目。
提示:请参阅 Right 函数。
语法
Left(string,length)
| 参数 | 描述 |
|---|---|
| string | 必需的。从其中返回字符的字符串。 |
| length | 必需的。规定需返回多少字符。如果设置为 0,则返回空字符串("")。如果设置为大于或等于字符串的长度,则返回整个字符串。 |
实例
例子 1
Module Module1Sub Main()dim txttxt="This is a beautiful day!"Console.WriteLine(Left(txt,11))End SubEnd Module
输出:
This is a b
例子 2
Module Module1Sub Main()dim txttxt="This is a beautiful day!"Console.WriteLine(Left(txt,100))End SubEnd Module
输出:
This is a beautiful day!
例子 3
Module Module1Sub Main()dim txt,xtxt="This is a beautiful day!"x=Len(txt)Console.WriteLine(Left(txt,x))End SubEnd Module
输出:
This is a beautiful day!