Delphi function to convert string to DOS format

I am using FINDSTR function to filter text files, but this is a fix for extended ASCII characters. I tried using the CharToOEM function, but I still have characters like "Γ " which FINDSTR doesn't seem to recognize.

I want to use FINDSTR because the text files I'm working with are 100MB in size, so I need something fast. Is there a function that renames strings so they don't have "strange" characters?

Code:

CharToOEM(PChar(lASCFileNameFull),PChar(lASCFileNameFull));
    renameFile(Format('%s.bak',[lASCFileNameFullBak]),Format('%s.bak',[lASCFileNameFull]));

    Si.dwFlags:=STARTF_USESHOWWINDOW;
    Si.wShowWindow:=SW_SHOWNORMAL;

    SetFileApisToOEM;
    CreateProcess(nil,pchar(Format('cmd.exe /K echo on && echo Processing filter...&& findstr "%s" %s.bak > %s',[commandString,lASCFileNameFull,lASCFileNameFull])),nil,nil,True,
    0,nil,nil,Si,Pi);
    WaitForSingleObject(pi.hProcess,INFINITE);
    SetFileApisToANSI;

      

Too bad, FINDSTR can't find the file ... Edit: This is Delphi 2007.

Edit: I was thinking about using a loop like:

while(!eof) do begin
  readLN(mySrcFile, currentLine);
  if strContains(currentLine, searchSyntax) then
    writeLN(destFile,currentLine);
end;

      

Unfortunately I cannot find such a "strContains" function (and it will probably be slow). The search string is not complicated at all, it is a bunch of HEX values: "C2 | 1AF | B8 | ..."

Final edit: Sometimes it's better to go back to basics :) I just replace all the extended characters with an underscore, checking the meaning of the character:

for I := 1 to length(lASCFileNameFull) do begin
  if integer(lASCFileNameFull[i])>127 then
    lASCFileNameFull[i]:='_';
end;

      

I hope someone will use this someday :) Thanks for the help Gram

+2


source to share


2 answers


Two things are needed to perform a sequential search:



  • You have to map the non-unicode language to the language used in the ansi-encoded. If this is not your current language, please change it temporarily:

    Control Panel \ Regional and Language Options \ Advanced \ Language for non-Unicode programs

  • to do a case insensitive search, you need to use the / i option on FindStr.

0


source


Why don't you just code it in Delphi? You can use plain text I / O (with a slightly larger file buffer), or go all the way and try with binary block access.



0


source







All Articles