Operator STRPTR (String pointer)


Returns the address of a string's character data.

Syntax:
Usage:
result = Strptr ( lhs )

Parameters:
lhs
A string.

Return Value:
Returns a Zstring Ptr to a string's character data (null value in case of empty string).

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.
In case of empty string (only for variable length strings), Operator Strptr returns a null pointer.

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.
When a variable length string is modified, the address of its descriptor remains always the same, but the the string's character data address (returned by Operator Strptr) may change (like any allocated memory that must be reallocated).
When a fixed length string is modified, the string's character data address (returned by Operator Strptr) is unchanged

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


Differences from QB:
See also:
Back to Pointer Operators
Back to String Operators
Back to Operators
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode