Pues si, ojo con los strings vacios
Código Delphi
[-]
function foo1(const s: string): string;
begin
if (s[1] = '/') and (s[2] = '/') then
Result := 'Hola'
else
Result := 'Adios';
end;
function foo2(const s: string): string;
const
MSG: array [Boolean] of string = ('Adios', 'Hola');
begin
Result := MSG[(s[1] = '/') and (s[2] = '/')];
end;
function foo3(const s: string): string;
begin
if s[1] + s[2] = '//' then
Result := 'Hola'
else
Result := 'Adios';
end;
begin
try
Writeln('Foo1 EmptyStr: ' + foo1('')); Writeln('Foo2 EmptyStr: ' + foo2('')); Writeln('Foo3 EmptyStr: ' + foo3('')); Writeln('Foo3 A: ' + foo3('A')); except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.