[fpc-devel] MoveChars - docs.embarcadero.com ...
jonas.maebe at elis.ugent.be
Sun Jul 22 20:43:06 CEST 2012
On 22 Jul 2012, at 20:18, silvioprog wrote:
> 2012/7/22, Jonas Maebe <jonas.maebe at elis.ugent.be>:
>> On 22 Jul 2012, at 04:54, silvioprog wrote:
>>> There MoveChars* function (or similar) native on Free Pascal?
>>> (*) -
>> As far as I can tell,
>> is exactly the same as
> Hm... I think that MoveChars copy a string to another string, but
> maintaining the contents of the second string (I'm without delphi for
> test it).
MoveChars just moves data. It has no special support for strings or anything else. See the example code on the Embarcadero site.
> So, I'll try to explain my problem ...
> I am needing to move a string to another string, eg:
> d, s: string;
> d := 'the on the table';
> s := 'books ';
> SetLength(d, Length(d) + Length(s));
> Move(s, d, Length(s));
This moves the contents of the string pointer (I suppose you are in a mode where string=ansistring), you have to use s instead.
> writeln(d); // the result should be 'the books on the table', but I
> get 'the|?S |?e table ?'
What you want is
d, s: string;
d := 'the on the table';
s := 'books ';
> I could easily do this using "copy", but I'm trying (without success)
> to do this at low level.
I would strongly recommend against it. You'll mainly run into problems by combining reference counted data and low level routines. The RTL versions already use the low level routines in the correct ways.
More information about the fpc-devel