[fpc-pascal] ansistrings access by character
L505
fpc505 at z505.com
Sat Jul 9 17:34:13 CEST 2005
|
| Or if you wanted to prepend exceptions rather than catch them, the following
| function could also work have worked (note you have to do a shortString cast,
| AnsiStrings don't like access by character)
|
I was under the same impression for a long time, but some of the FPC RTL sources
use ansistrings and access by character. The findpart function for example uses
ansistrings but accesses by string[n]
For example this compiles and runs.
var
test:ansistring;
function IsANumber (InStr : AnsiString) : Boolean;
var
TempBool: Boolean;
Str: ansiString;
I: Integer;
begin
Str := InStr;
TempBool := True;
I := 1;
while (I <= Length(Str)) and (TempBool = True) do
begin
TempBool := Str[I] in ['0'..'9'];
Inc(I);
end;
IsANumber := TempBool
end;
begin
test:='testing';
test[1]:='p';
writeln(test);
test:='5453tyy';
if IsANumber(test) then
writeln('yes '+test+' is a number')
else
writeln('no, '+test+' is not a number');
test:='545365';
if IsANumber(test) then
writeln('yes '+test+' is a number')
else
writeln('no, '+test+' is not a number');
readln;
end.
So can someone shed the light? Is it just a rumor that ansistrings shouldn't be
accessed by character? Only specific situations?
More information about the fpc-pascal
mailing list