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

  • 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)
  • Re: A note on computing thugs and coding bums
    ... code is valid for any character set that is legal in C (which is a ... characters in the required source character set ... A String, in C Sharp or Java, can be redefined. ... allow programmers to handle some other data format, ...
    (comp.programming)
  • Re: input & output in assembly
    ... [As you've not specified OS or assembler, ... using individual character I/O and handling the rest yourself in your ... it finds in that string, ... ENTER key is pressed (maximum buffer size: ...
    (comp.lang.asm.x86)