
|
<<
Index
>>
|
FutureBasic
|
mid, mid$, mid$$
|
|
statement
|
|
Syntax
mid(
CFMutableStringVar, startPos, numChars ) =
replaceCFString
mid$(
PascalStringVar, startPos, numChars ) =
replacePascalString
mid$$(
container$$, startPos, numChars ) =
replacePascalString/
contnr$$
Description
This statement updates a CFMutableStringVar, PascalStringVar or container$$, deleting a subpart from CFMutableStringVar, PascalStringVar or container$$ and replacing it with an equal number of characters from the left side of replaceCFString or replacePascalString. The subpart to be replaced begins at position startPos within CFMutableStringVar, PascalStringVar or container$$. In the following code fragments, containers and strings work the same.
The number of characters replaced equals the smallest of these quantities:
- numChars
- the length of replaceCFString/replacePascalString
- the length of CFMutableStringVar/PascalStringVar - startPos + 1
Under the following circumstances, mid/mid$,mid$$ does nothing:
- When CFMutableStringVar/PascalStringVar or replaceCFString/replacePascalString is empty;
- When startPos is less than 0 or greater than the length of CFMutableStringVar;
- When startPos is less than 1 or greater than the length of PascalStringVar;
- When numChars is less than 1.
Note
You may not use complex expressions that include containers on the right side of the equal sign.
mid example
CFMutableStringRef s1 =
fn MutableStringWithCapacity(0)
CFMutableStringRef s2 =
fn MutableStringWithCapacity(0)
CFMutableStringRef s3 =
fn MutableStringWithCapacity(0)
MutableStringSetString( s1, @"abcdefgh" )
MutableStringSetString( s2, @"abcdefgh" )
MutableStringSetString( s3, @"abcdefgh" )
mid( s1, 1, 3 ) = @"1234"
NSLog(@"%@",s1)
// a123efgh
mid( s2, 1, 5 ) = @"1234"
NSLog(@"%@",s2)
// a1234fgh
mid( s3, 6, 4 ) = @"1234"
NSLog(@"%@",s3)
// abcdef12
mid$ example
x$ = "abcdefgh"
y$ = "abcdefgh"
z$ = "abcdefgh"
mid$(x$,2,3) = "1234"
print x$
mid$(y$,2,5) = "1234"
print y$
mid$(z$,7,4) = "1234"
print z$
program output:
a123efgh
a1234fgh
abcdef12
See also
mid function; left; right; instr