Does anyone know how to use pointers to strings? I find the
manual very skimpy on this. Can anyone give me an example? Thanks in advance.
Pat
manual very skimpy on this. Can anyone give me an example? Thanks in advance.
Pat
cls DIM a AS STRING DIM b AS STRING PTR DIM c AS BYTE PTR DIM d as integer a = CHR$(34) + "A PowerBASIC Dynamic String!" + CHR$(34) PRINT "The original string is " a b = VARPTR32(a) PRINT "The pointer is located at " HEX$(b) PRINT "The target of the pointer is " @b PRINT PRINT "Now lets look at the data in the string itself:" c = STRPTR32(@b) ' we could also use c = STRPTR32(a) PRINT "The string data is located at " HEX$(c) PRINT "The data (byte-by-byte) is "; FOR d = 1 to LEN(@b) PRINT CHR$(@c); incr c NEXT PRINT PRINT PRINT "Now lets do that again using indexed pointers:" PRINT "The data (byte-by-byte) is "; c = STRPTR32(a) ' we could also use STRPTR32(@b) FOR d = 0 to LEN(a) - 1 PRINT CHR$(@c[d]); NEXT PRINT : PRINT PRINT "Clear as mud?"
DIM a AS STRING DIM b AS STRING PTR a = CHR$(34) + "A PowerBASIC Dynamic String!" + CHR$(34) b = VARPTR32(a) PRINT MyFunction(a) print MyFunction(@b) FUNCTION MyFunction(x as string) as string FUNCTION = "Received = " + x END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment