Board index » delphi » Re: String Index Replacement

Re: String Index Replacement


2003-08-12 12:38:32 AM
delphi166
"Bob Goldstine" <XXXX@XXXXX.COM>writes
3f37c55a$XXXX@XXXXX.COM...
Quote
In D7, the following code gives me an "Unsafe code, string index to var
param" error: Whats the proper way to do this?

for i := 1 to Length(aString) do begin
if aString[i] = 'X' then aString[i] := 'Y';
end;
As follows:
for i := 1 to Length(aString) do begin
if aString[i] = 'X' then {$WARNINGS OFF}aString[i] := 'Y'{$WARNINGS
ON};
end;
Cheers,
Ignacio
 
 

Re: String Index Replacement

That tells how to eliminate the warning, the question was what is the proper
way.
 

Re: String Index Replacement

"D Whaley" <XXXX@XXXXX.COM>writes
3f37f0af$XXXX@XXXXX.COM...
Quote
That tells how to eliminate the warning, the question was what is the
proper way.
In this case the warning is bogus; that /is/ the correct way.
Both Delphi and JCL have some functions that can do it, but they're not as
fast as iterating through the string yourself.
Cheers,
Ignacio
 

Re: String Index Replacement

Thanx.
Quote
In this case the warning is bogus; that /is/ the correct way.
 

Re: String Index Replacement

In article <3f37f3d6$XXXX@XXXXX.COM>, "Ignacio Vazquez"
<ivazquezATorioncommunications.com>writes:
Quote
In this case the warning is bogus; that /is/ the correct way.
sure?
I think this warning has to do with portability to Dot.Net.
Of course if you never intend to do this it is bogus all right. <g>