Mid
From REALbasicWiki
Contents |
[edit] Prototype
Function Mid(s as String, start as Integer) as Integer Function Mid(s as String, start as Integer, length as Integer) as Integer
[edit] Description
Mid returns the substring starting at the 1-based character index start. The second form returns the substring starting at start of length length.
[edit] Discussion
Mid uses the string's encoding to parse the string into characters. If the encoding is nil, Mid operates on bytes, like MidB.
Experiment shows that Mid handles out-of-range parameters as follows.
- If length < 1, Mid(s, start, length) returns "".
- If start + length > Len(s) + 1, Mid(s, start, length) returns the same string as Mid(s, start).
- If start < 1, then Mid(s, start, length) returns the same string as Mid(s, 1, start + length - 1)
(REALbasic 2007r5, Mac OS 10.5.1)
[edit] Sample Code
Mid("This is a test", 4) = "s is a test"
Mid("This is a test", 1, 4) = "This"
Mid("This is a test", 11) = "test"
