Mid (函数)
 
返回字符串的子字符串

语法

Declare Function Mid ( ByRef str as Const String, ByVal start as integer ) as String
Declare Function Mid ( ByVal str as Const WString Ptr, ByVal start as integer ) as WString
Declare Function Mid ( ByRef str as Const String, ByVal start as integer, ByVal n as integer ) as String
Declare Function Mid ( ByVal str as Const WString Ptr, ByVal start as integer, ByVal n as integer ) as WString

用法

result = Mid[$]( str , start [, n ] )

参数

str
源字符串。
start
子字符串的str 中的起始位置。第一个字符从位置1开始。
n
子字符串长度,以字符为单位。

说明

返回从str start 开始的子字符串。如果str 为空,则返回空字符串("")。如果start <= 0则返回null字符串("")。

Mid的第一种形式中,返回所有剩余的字符。在第二种形式中,如果n < 0n >= len(str )则返回所有剩余的字符。

例子

Print Mid("ABCDEFG", 3, 2)
Print Mid("ABCDEFG", 3)
Print Mid("ABCDEFG", 2, 1)

将产生输出:
cd
cdefg
b
一个Unicode示例:
Wiki:以这种方式渲染的代码允许显示Unicode字符。

 

平台差异

  • DOS不支持{999796001}Mid{999796002}的宽字符串版本。

方言差异

  • -lang qb 方言中的字符串类型后缀“$ ”是必需的。
  • -lang fblite -lang fb 方言中,字符串类型后缀“$ ”是可选的。

与QB差别

  • QB不支持Unicode。

参考
昏暗的文字wstring * 20
text =“Привет,мир!”
打印中间(文字,6,4)'显示“т”,м“