unit Unit11;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm11 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure SearchStringList(AList: TStringList);
procedure SearchStringFindNLSString(AList: TStringList);
procedure SearchStringFindNLSStringEx(
const LOCALE_NAME:
string; AList: TStringList);
end;
var
Form11: TForm11;
implementation
{$R *.dfm}
const
SUB_STR_1 = '
Götterdämmerung';
SUB_STR_2 = '
Götterdämmerung';
procedure TForm11.FormCreate(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm11.SearchStringFindNLSString(AList: TStringList);
procedure DoFindWithFindNLSString(
const SubStr:
string);
var
i, Res, Found: Integer;
begin
for i := 0
to AList.Count - 1
do
begin // LOCALE_USER_DEFAULT = $400
Res := FindNLSString(LOCALE_USER_DEFAULT, FIND_FROMSTART, PChar(AList.Strings[i]), -1, PChar(SubStr), -1, @Found);
if (Res <> -1)
and (Found > 0)
then
Memo1.Lines.Add(IntToStr(i));
end;
end;
begin
Memo1.Lines.Add('
finding lines with SUB_STR_1 = ' + SUB_STR_1);
DoFindWithFindNLSString(SUB_STR_1);
Memo1.Lines.Add('
finding lines with SUB_STR_2 = ' + SUB_STR_2);
DoFindWithFindNLSString(SUB_STR_2);
end;
procedure TForm11.SearchStringFindNLSStringEx(
const LOCALE_NAME:
string; AList: TStringList);
procedure DoFindWithFindNLSStringEx(
const SubStr:
string);
var
i, Res, Found: Integer;
begin
for i := 0
to AList.Count - 1
do
begin
Res := FindNLSStringEx(PChar(LOCALE_NAME), FIND_FROMSTART, PChar(AList.Strings[i]), -1, PChar(SubStr), -1, @Found,
nil,
nil, 0);
if (Res <> -1)
and (Found > 0)
then
Memo1.Lines.Add(IntToStr(i));
end;
end;
var
i, Res, Found: Integer;
begin
Memo1.Lines.Add('
finding lines with SUB_STR_1 = ' + SUB_STR_1);
DoFindWithFindNLSStringEx(SUB_STR_1);
Memo1.Lines.Add('
finding lines with SUB_STR_2 = ' + SUB_STR_2);
DoFindWithFindNLSStringEx(SUB_STR_2);
end;
procedure TForm11.SearchStringList(AList: TStringList);
procedure DoFindWithPos(
const SubStr:
string);
var
i: Integer;
begin
for i := 0
to AList.Count - 1
do
if Pos(SubStr, AList.Strings[i]) > 0
then
Memo1.Lines.Add(IntToStr(i));
end;
begin
Memo1.Lines.Add('
finding lines with SUB_STR_1 = ' + SUB_STR_1);
DoFindWithPos(SUB_STR_1);
Memo1.Lines.Add('
finding lines with SUB_STR_2 = ' + SUB_STR_2);
DoFindWithPos(SUB_STR_2);
end;
procedure TForm11.Button1Click(Sender: TObject);
var
sList: TStringList;
i: Integer;
begin
sList := TStringList.Create;
try
sList.LoadFromFile('
MacOS_ItunesContent_Small.txt');
if sList.Count = 0
then
Exit;
for i := 0
to sList.Count - 1
do
Memo2.Lines.Add(IntToStr(i) + #9 + sList.Strings[i]);
Memo1.Lines.Add('
Searching using Pos');
SearchStringList(sList);
Memo1.Lines.Add(#13#10'
Searching with FindNLSString');
SearchStringFindNLSString(sList);
Memo1.Lines.Add(#13#10'
Searching with FindNLSStringEx and LOCALNAME=''
''
');
SearchStringFindNLSStringEx('
', sList);
finally
sList.Free;
end;
end;
end.