ok i made this example PUBLIC SUB Main() DIM p AS Pointer DIM s AS String DIM a AS String = "this is a string" & Chr$(0)
PRINT Len(a) PRINT InStr(a, Chr$(0)) p = Alloc(a) 'READ #p, s s = StrPtr(p) PRINT Len(s) PRINT InStr(s, Chr$(0)) Free(p) END --------------------- Before StrPtr(p) then Len and InStr() shows 17 characters, ok! After StrPtr(p) the last zero terminated character seems to be disapeared. The Len is 16 and InStr() does not find the chr$(0). Did i do something wrong? On Sun, 2010-12-12 at 19:01 +0100, Benoît Minisini wrote: > > i just compared the output > > with PRINT s and i saw the same result. > > > > i was wrong because i did not know about string manipulation in c. > > i did not understand the zero terminated string you mentioned in help. > > > > i found some info at this page > > http://www.dfstermole.net/OAC/hstrings.html > > > > Is there any way to produce a zero terminated string in Gambas to > > demostrate the StrPtr()? > > > > Yes, but I don't want to really explain that, as it is internal interpreter > stuff. > > Even if Gambas always knows the length of a string (by storing it with the > string contents for example), all strings created by Gambas are zero- > terminated string. > > *But*, Gambas does not always create strings. For example, many string > manipulation functions (Mid$, Left$, Right$, Trim$...) do not really create > strings to be faster, and so do not return zero-terminated strings > necessarily. > > So, to be sure, just create a string with an explicit Chr$(0) at its end. > > Regards, > -- Regards, Demosthenes ------------------------------------------------------------------------------ Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL, new data types, scalar functions, improved concurrency, built-in packages, OCI, SQL*Plus, data movement tools, best practices and more. http://p.sf.net/sfu/oracle-sfdev2dev _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user