Re: copy one character from a string.
- From: Dodgy <Dodgy@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 Nov 2005 11:09:49 +0000
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
.
- Follow-Ups:
- Re: copy one character from a string.
- From: MLian
- Re: copy one character from a string.
- References:
- copy one character from a string.
- From: MLian
- copy one character from a string.
- Prev by Date: Re: "HTTP 1.1 302 found" message with Indy
- Next by Date: Re: copy one character from a string.
- Previous by thread: copy one character from a string.
- Next by thread: Re: copy one character from a string.
- Index(es):
Relevant Pages
|
|