以下代码均没有考虑有空行和特殊字符的情况:
1、删除第一个字符:- @echo off&setlocal enabledelayedexpansion
- (for /f "delims=" %%a in (a.txt) do (
- if not defined str (
- set "str=%%a"&echo !str:~1!
- ) else (
- echo %%a
- )
- ))>tem
- del /q a.txt&ren tem a.txt
复制代码 2、删除最后一个字符- @echo off&setlocal enabledelayedexpansion
- (for /f "delims=" %%a in (a.txt) do (
- if defined str echo !str!
- set "str=%%a"
- )
- echo !str:~,-1!)>tem
- del /q a.txt&ren tem a.txt
复制代码 3、至于删除指定位置的字符:- @echo off&setlocal enabledelayedexpansion
- set /p h=请输入要删除的字符所在的行数:
- set /p s=请输入要删除本行的第几个字符:
- set /a s1=s-1
- (for /f "delims=" %%a in (a.txt) do (
- set /a n+=1
- if "!n!" equ "%h%" (
- set "str=%%a"&echo !str:~,%s1%!!str:~%s%!
- ) else (
- echo %%a
- )
- ))>tem
- del /q a.txt&ren tem a.txt
复制代码
[ 本帖最后由 batman 于 2011-2-26 18:36 编辑 ] |