Operator Strptr (String Pointer)
Returns the address of a string's character data.
Declare Operator StrPtr ( ByRef lhs As String ) As ZString Ptr
Declare Operator StrPtr ( ByRef lhs As WString ) As ZString Ptr
result = StrPtr ( lhs )
lhs
This operator returns a ZString Ptr that points to the beginning of a string's character data. Operator Strptr is the proper method for acquiring the address of a string's character data.
Note that when passed a WString, Operator Strptr still returns a ZString Ptr, which may not be the desired result.
The related Operator Varptr (Variable Pointer) and Operator @ (Address Of), when used with a String, return the address of the internal string descriptor.
Syntax
Declare Operator StrPtr ( ByRef lhs As String ) As ZString Ptr
Declare Operator StrPtr ( ByRef lhs As WString ) As ZString Ptr
Usage
result = StrPtr ( lhs )
Parameters
lhs
A string.
Return Value
Description
This operator returns a ZString Ptr that points to the beginning of a string's character data. Operator Strptr is the proper method for acquiring the address of a string's character data.
Note that when passed a WString, Operator Strptr still returns a ZString Ptr, which may not be the desired result.
The related Operator Varptr (Variable Pointer) and Operator @ (Address Of), when used with a String, return the address of the internal string descriptor.
Example
'' This example uses Strptr to demonstrate using pointers with strings
Dim myString As String
Dim toMyStringDesc As Any Ptr
Dim toMyString As ZString Ptr
'' Note that using standard VARPTR notation will return a pointer to the
'' descriptor, not the string data itself
myString = "Improper method for Strings"
toMyStringDesc = @myString
Print myString
Print Hex( toMyStringDesc )
Print
'' However, using Strptr returns the proper pointer
myString = "Hello World Examples Are Silly"
toMyString = StrPtr(myString)
Print myString
Print *toMyString
Print
'' And the pointer acts like pointers to other types
myString = "MyString has now changed"
Print myString
Print *toMyString
Print
Dim myString As String
Dim toMyStringDesc As Any Ptr
Dim toMyString As ZString Ptr
'' Note that using standard VARPTR notation will return a pointer to the
'' descriptor, not the string data itself
myString = "Improper method for Strings"
toMyStringDesc = @myString
Print myString
Print Hex( toMyStringDesc )
'' However, using Strptr returns the proper pointer
myString = "Hello World Examples Are Silly"
toMyString = StrPtr(myString)
Print myString
Print *toMyString
'' And the pointer acts like pointers to other types
myString = "MyString has now changed"
Print myString
Print *toMyString
Differences from QB
- New to FreeBASIC, but does exactly the same thing as SAdd
See also