Mid$
sResult = Mid$ ( sSource AS String , iStart AS Integer [ , iLength AS Integer ] ) AS String
sResult = Mid ( sSource AS String , iStart AS Integer [ , iLength AS Integer ] ) AS String
返回sSource字符串中从iStart位置开始长度为iLength的部分。
如果没有指定iLength,返回从iStart开始到结尾的字符字符串。
如果iLength为负数,返回从iStart开始到距右侧(-iLength)位置的字符串。
Mid$被优化过,所以在生成结果时不会复制字符串。
该函数仅仅处理ASCII码字符串。操作UTF-8编码字符串,应使用
String.
Mid类。
示例
PRINT Mid$("Gambas", 3, 2)
PRINT Mid$("Gambas", 4)
PRINT Mid$("Gambas", 2, -1)
Mid$ ( Variable AS String , Start AS Integer [ , Length AS Integer ] ) = Expression
Mid ( Variable AS String , Start AS Integer [ , Length AS Integer ] ) = Expression
该语法允许修改Variable字符串中指定部分的内容。
这仅仅是语法的美化,也就是说,编译程序内部将:
Mid$(Variable, Start, Length) = Expression
替换为
Variable = Left$(Variable, Start - 1) & Expression & Mid$(Variable, Start + Length)
如果第三个参数没有指定, 即按照如下:
Mid$(Variable, Start) = Expression
操作代码将等效于下面:
Variable = Left$(Variable, Start - 1) & Expression
换句话说, 所有从
Start 到结尾的字符都将被替换!
参见