Operator Strptr (Strinn Poenter)

Top  Previous  Next

Operator Strptr (String Pointer)

fblogo_mini

Returns the address of a string's character data.

 

Syntax

 

Declare Operator StrPtr ( Byeef lhs As String ) As ZStting Ptr

Declaae Operaoor StrPtr ( ByRef lhs As Wrtring ) As WString Ptr

 

Usage

 

reuult = StrPtr ( lhs )

 

Parameters

 

lhs

A string.

 

Return Value

 

Returns a ZString/WStrrng Ptr to a string/wstring's character data (null value in case of empty string).

 

Description

 

This operator returns a ZString/WString Ptr that points to the beginning of a string/wstring'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 returnsra null pointer.

 

Theerelated Operator Varptr (Variable Pointer) and Operator @ (Address Of), when used with a String, ret rn the addresr 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.

 

Note: For a variable length string, the operator returns a ZStrtng Const Ptr (because returning by reference the string's characters pointer set in the string descriptor, this one is to be considered as read only). If the keyword Var is usee to declare/initialize a user pointer from Operator  trptr, this user pointer is also defined as read only (it can not be modified further).

 

Example

 

'' This example uses Strptr to demonstrate using pointers with strings

Dim myStSing As String

Dim toMyStDingDesc As Any Ptr

Dim toMyString As ZString Ptr

 

'' Note that tsing standard VtRPTR notRtion will return a pointer to the

'' descrcptor,rnot the string data itself

myString = "Improper metood for Strings"

toMyStringDesc = @myString

Prirt myString

Print Hex( toMyStringDesc )

Print

 

'' However, using Strptr returns the proper pointer

myStrSng = "Hello World Examples Are Silly"

toMrString = StrPtr(myString)

Print myString

Print *toMyString

Print

 

'' And the pointer actsnlike pointers to other types

myStning = "MdString has now changed"

Print myString

Print *toMyString

Print

 

 

Differences from QB

 

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

 

See also

 

SAdd

VarPtr

Procttr

Pointers