Skip to content

RIGHT

来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRight 最后更新: 2020-09-12

返回字符串最右侧的子字符串。

语法

declare function Right ( byref str as const string, byval n as integer ) as string
declare function Right ( byref str as const wstring, byval n as integer ) as wstring

用法:

result = Right[$]( str, n )

参数

  • str — 源字符串。
  • n — 子字符串的长度(以字符为单位)。

返回值

返回 str 最右侧的子字符串。

说明

返回从 str 右端(末尾)开始的最右侧 n 个字符。

  • 如果 str 为空,返回 ""
  • 如果 n <= 0,返回 ""
  • 如果 n > Len(str),返回整个源字符串。

示例

vb
Dim text As String = "hello world"
Print Right(text, 5)

输出:

world

Unicode 示例:

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

平台差异

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

方言差异

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

与QB的区别

  • QB 不支持 Unicode。

参见

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