case insensitive Pos

前端 未结 9 1516
一个人的身影
一个人的身影 2021-02-02 00:56

Is there any comparable function like Pos that is not case-sensitive in D2010 (unicode)?

I know I can use Pos(AnsiUpperCase(FindString), AnsiUpperCase(SourceString)) but

9条回答
  •  梦谈多话
    2021-02-02 01:15

    The built-in Delphi function to do that is in both the AnsiStrings.ContainsText for AnsiStrings and StrUtils.ContainsText for Unicode strings.

    In the background however, they use logic very similar to your logic.

    No matter in which library, functions like that will always be slow: especially to be as compatible with Unicode as possible, they need to have quite a lot of overhead. And since they are inside the loop, that costs a lot.

    The only way to circumvent that overhead, is to do those conversions outside the loop as much as possible.

    So: follow your own suggestion, and you have a really good solution.

    --jeroen

提交回复
热议问题