2
votes

Today I was fixing up some warnings in our code and one of them is "W1058 Implicit string cast with potential data loss from 'string' to 'AnsiString'" in ContainsStr function.

After searching for a while for an equivalent of this function which takes two unicode strings as an argument I've decided to ask here. I would expect to find something like ContainsWideStr (for Delphi 2007 and lower) or ContainsUnicodeStr (for Delphi 2009+) but I couldn't find any of these.

I know I could just do something like this on my own:

function ContainsUnicodeStr(const AText, ASubText: String): Boolean;
begin
  Result := Pos(ASubText, AText) > 0;
end;

However, I would like to avoid duplication of code which is already in Delphi, but I simply do not know where.

1
If anywhere, it should be in the same unit that contains the ContainsStr function? Unless that is in some unit with Ansi in its name, then I would expect it to be in the strutils unit.Marjan Venema
The routine described here takes two Unicode strings.Uli Gerhardt
Thanks, somehow I've got blocked and forgot to check this core unit! :)Wodzu

1 Answers

4
votes

According to the documentation, StrUtils.ContainsStr works with Unicode. But of course, AnsiStrings.ContainsStr does not.