Skip to content

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)

输出:

hello

Unicode 示例:

vb
Dim text As WString * 20
text = "Привет, мир!"
Print Left(text, 6)  'displays "Привет"

平台差异 ​

  • DOS 不支持 Left 的宽字符字符串版本。

方言差异 ​

  • 在 -lang qb 方言中,字符串类型后缀 $ 是必须的。
  • 在 -lang fblite 方言中,字符串类型后缀 $ 是可选的。
  • 在 -lang fb 方言中,字符串类型后缀 $ 被忽略。

与 QB 的差异 ​

  • QB 不支持 Unicode。

另请参阅 ​

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系