Re: copy one character from a string.



On 23 Nov 2005 02:21:20 -0800, "MLian" <mettelian@xxxxxxxxxxx> waffled
on about something:

>I want to copy a string - character by character like this:
>
>Mystr [ i ] := Yourstr[ j ]
>
>(i and j are incremented)
>
>Now, this doesn't work so I wonder how it would look
>like using copy, typecast, or any other way to do the trick.
>
>
>
>Thanks,
>MetteLian

Oh yes it does.

var str1,str2:string;
begin
str1:='aaaaaa';
str2:='uvwxyz';
str1[3]:=str2[3];
showmessage(str1+#13+str2);
end;

I suspect the problem you are having is because your destination
string Mystr[i] is empty, and has no length. This means that the
moment you refer to Mystr[1] you are referring beyond it's memory
allocation and *bang*.

You can use
setlength(mystr,length(yourstr))
To reserve the space.

Also note that when accessing chars from a string this way, the first
character is at offset 1, and not offset 0.

Hope this helps

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
.



Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... chars + swap move ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)