windows 脚本将适当的字符添加到 .txt

The windows script adding the appropriate characters to .txt

我想创建一个脚本,它将变成 sql 形式的命令,可以分配给 Delphi 中的字符串。示例(.txt 文件中的文本):

select name,species,quantity from lamas
where species='Alpaca'
and name='Andrew'

我要:

  'select name,species from lamas '+
  'where species='Alpaca' '+
  'and name='Andrew' ';

我会在每行 txt 文件的开头添加 ' 在行尾 '+' 而在结束文件上 '+' 简单 ';.

这是 Windows CMD 脚本:

@echo OFF
setlocal enableDelayedExpansion
set j="@@@@@"
for /F "tokens=1 delims=" %%i in ('type %1') do (

  IF  NOT !j!== "@@@@@" (
   echo '!j!'+ >>output.txt   
  )

  set j=%%i
  set j=!j:'=''!
)
echo '!j!'; >>output.txt

如果您使用 .txt 文件参数调用它

script.cmd example.txt

您将获得 output.txt 文件:

'select name,species,quantity from lamas'+    
'where species=''Alpaca'''+    
'and name=''Andrew'''; 

注意:在 Delphi 中,您还应该在 SQL 命令中将字符串 ('Alpaca'、'Andrew') 周围的单引号更改为双引号。这个脚本实现了这个。