LEFT
来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgLeft 最后更新: 2020-09-12
返回字符串最左侧的子字符串。
语法
declare function Left ( byref str as const string, byval n as integer ) as string
declare function Left ( byref str as const wstring, byval n as integer ) as wstring用法:
result = Left[$]( str, n )参数
- str — 源字符串。
- n — 从源字符串中返回的字符数。
返回值
返回 str 最左侧的子字符串。
说明
返回从 str 左侧(起始处)开始的最左侧 n 个字符。
- 若
str为空,返回""。 - 若
n <= 0,返回""。 - 若
n > Len(str),返回整个源字符串。
示例
vb
Dim text As String = "hello world"
Print Left(text, 5)输出:
helloUnicode 示例:
vb
Dim text As WString * 20
text = "Привет, мир!"
Print Left(text, 6) 'displays "Привет"平台差异
- DOS 不支持
Left的宽字符字符串版本。
方言差异
- 在
-lang qb方言中,字符串类型后缀$是必须的。 - 在
-lang fblite方言中,字符串类型后缀$是可选的。 - 在
-lang fb方言中,字符串类型后缀$被忽略。
与 QB 的差异
- QB 不支持 Unicode。