FutureBasic Logo

<<    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:

Under the following circumstances, mid/mid$,mid$$ does nothing:
Notes
• CFMutableStrings are zero-based, which means the first character of the string is at position 0.
• The first character of a pascal string or container is at position 1.
• 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

Str255 x, y, z
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