Delphi中StrUtils的SearchBuf为何对长尾词搜索表现异常?
- 内容介绍
- 文章标签
- 相关推荐
本文共计285个文字,预计阅读时间需要2分钟。
我正在整理使用FastStrings的旧代码,并且已经实现了我的PosAnyCase的旧例子。它应该像Pos一样操作。+(我希望SearchBuf在两个字符串上调用UpperCase更好)。function PosAnyCase(const A)
function PosAnyCase( const AFindStr, AStr : string ) : integer; // Returns the position of this substring within a string ignoring case
我正在使用SearchBuf如下:
function PosAnyCase( const AFindStr, AStr : string ) : integer; // Returns the position of this substring within a string ignoring case var Start, ResultPos : PChar; begin Start := PChar( AStr ); ResultPos := SearchBuf( Start, ByteLength( AStr ), 0, 0, AFindStr, [soDown] ); if ResultPos = nil then Result := 0 else Result := ResultPos-Start+1; end;
当我从单元测试中调用此例程时,以下测试通过:
Check( PosAnyCase( '', '123' ) = 0 ); Check( PosAnyCase( '2', '123' ) = 2 ); Check( PosAnyCase( 'A', 'ABC' ) = 1 ); Check( PosAnyCase( 'a', 'ABC' ) = 1 ); Check( PosAnyCase( 'the', 'hellot there' ) = 8 ); Check( PosAnyCase( 'THE', 'hellot there' ) = 8 );
但是这个测试失败了:
Check( PosAnyCase( 'nice', 'does not have n i c e' ) = 0 );
我做错了什么? SearchBuf上的文档非常有限….
谢谢
本文共计285个文字,预计阅读时间需要2分钟。
我正在整理使用FastStrings的旧代码,并且已经实现了我的PosAnyCase的旧例子。它应该像Pos一样操作。+(我希望SearchBuf在两个字符串上调用UpperCase更好)。function PosAnyCase(const A)
function PosAnyCase( const AFindStr, AStr : string ) : integer; // Returns the position of this substring within a string ignoring case
我正在使用SearchBuf如下:
function PosAnyCase( const AFindStr, AStr : string ) : integer; // Returns the position of this substring within a string ignoring case var Start, ResultPos : PChar; begin Start := PChar( AStr ); ResultPos := SearchBuf( Start, ByteLength( AStr ), 0, 0, AFindStr, [soDown] ); if ResultPos = nil then Result := 0 else Result := ResultPos-Start+1; end;
当我从单元测试中调用此例程时,以下测试通过:
Check( PosAnyCase( '', '123' ) = 0 ); Check( PosAnyCase( '2', '123' ) = 2 ); Check( PosAnyCase( 'A', 'ABC' ) = 1 ); Check( PosAnyCase( 'a', 'ABC' ) = 1 ); Check( PosAnyCase( 'the', 'hellot there' ) = 8 ); Check( PosAnyCase( 'THE', 'hellot there' ) = 8 );
但是这个测试失败了:
Check( PosAnyCase( 'nice', 'does not have n i c e' ) = 0 );
我做错了什么? SearchBuf上的文档非常有限….
谢谢

