Operator Strptr (String Pointer)

FreeBASIC

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.

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


Differences from QB

  • New to FreeBASIC, but does exactly the same thing as SAdd

See also