Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-07

MoveChars - docs.embarcadero.com ...

8 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi,

There MoveChars* function (or similar) native on Free Pascal?

(*) - http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_MoveChars.html

Thanks,

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

silvioprog
to Jonas Maebe

2012/7/22, Jonas Maebe :

Show quoted text 18 lines
On 22 Jul 2012, at 04:54, silvioprog wrote: > There MoveChars* function (or similar) native on Free Pascal? > > (*) - > http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_MoveChars.html As far as I can tell, MoveChars(Source,Dest,Length); is exactly the same as Move(Source,Dest,Length*2); Jonas

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).

So, I'll try to explain my problem ...

I am needing to move a string to another string, eg:

var
  d, s: string;
begin
  d := 'the on the table';
  s := 'books ';
  SetLength(d, Length(d) + Length(s));
  Move(s, d[4], Length(s));
  writeln(d); // the result should be 'the books on the table', but I
get 'the|?S  |?e table  ?'
end;

I could easily do this using "copy", but I'm trying (without success) to do this at low level.

Thank you Jonas! :)

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Jonas Maebe
to silvioprog: 2012/7/22, Jonas Maebe : Hm... I think that MoveChars copy a string to another string, but
silvioprog wrote 20 lines
2012/7/22, Jonas Maebe : > > On 22 Jul 2012, at 04:54, silvioprog wrote: > >> There MoveChars* function (or similar) native on Free Pascal? >> >> (*) - >> http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_MoveChars.html > > As far as I can tell, > > MoveChars(Source,Dest,Length); > > is exactly the same as > > Move(Source,Dest,Length*2); 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.

Show quoted text 11 lines
So, I'll try to explain my problem ... I am needing to move a string to another string, eg: var d, s: string; begin d := 'the on the table'; s := 'books '; SetLength(d, Length(d) + Length(s)); Move(s, d[4], 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[1] instead.

writeln(d); // the result should be 'the books on the table', but I get 'the|?S |?e table ?'

What you want is

var
 d, s: string;
begin
 d := 'the on the table';
 s := 'books ';
 insert(s,d,4);
 writeln(d);
end; 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.

Jonas

Reply by email

silvioprog
to Jonas Maebe

2012/7/22, Jonas Maebe :

Show quoted text 64 lines
On 22 Jul 2012, at 20:18, silvioprog wrote: > 2012/7/22, Jonas Maebe : >> >> On 22 Jul 2012, at 04:54, silvioprog wrote: >> >>> There MoveChars* function (or similar) native on Free Pascal? >>> >>> (*) - >>> http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_MoveChars.html >> >> As far as I can tell, >> >> MoveChars(Source,Dest,Length); >> >> is exactly the same as >> >> Move(Source,Dest,Length*2); > > 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: > > var > d, s: string; > begin > d := 'the on the table'; > s := 'books '; > SetLength(d, Length(d) + Length(s)); > Move(s, d[4], 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[1] instead. > writeln(d); // the result should be 'the books on the table', but I > get 'the|?S |?e table ?' What you want is var d, s: string; begin d := 'the on the table'; s := 'books '; insert(s,d,4); writeln(d); > end; > 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. Jonas

I'll use Insert, because now I can see what is really recommended. :)

Thank you again Jonas!

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

silvioprog
to Hans-Peter Diettrich

2012/7/22, Hans-Peter Diettrich :

Show quoted text 6 lines
silvioprog schrieb: > I could easily do this using "copy", but I'm trying (without success) > to do this at low level. ...where you get what you asked for ;-)

:)

Why do you want to do things at low level, which can be done easily on high level? DoDi

Is only in a specific case... I'm creating some useful functions for working with CGI (I'm extracting some ideas from PHP).

Silvio Clécio My public projects - github.com/silvioprog

Reply by email