First, let's talk about the issues of blank lines and spaces. The following is the code:
- @echo off
- echo --------------------------
- for /f %%i in (a.xml) do echo --"%%i"--
- echo --------------------------
- for /f "tokens=*" %%i in (a.xml) do echo --"%%i"--
- echo --------------------------
- for /f "tokens=* delims=" %%i in (a.xml) do echo --"%%i"--
- echo --------------------------
- for /f "tokens=* delims=/" %%i in (a.xml) do echo --"%%i"--
- echo --------------------------
- pause
hxuan?表ー: 2006-11-24 11:22
Among the four FORs, the first result is that all blank lines, space lines, and tab lines in the a.xml file are not output, and only the characters between the first space and space, space and tab, tab and tab in each line are output. That is to say, spaces and tabs are used as default delimiters, and only the first content after separation is output. At this time, using %%j cannot output the second content.
The second result is that blank lines are not output, space lines become blank lines output, tab lines become blank lines output, and the spaces and tabs at the front of each line are also not output. This is why space lines and tab lines become blank lines.
The third result has no blank lines output, and the others are output as original.
The fourth result has the same result as the third. The delimiter here can be changed to others, of course, except for some special characters.
So, spaces and tabs are mainly issues of delimiters, which can be solved.
The code is modified as follows:
- @echo off
- setlocal enabledelayedexpansion
- set /a a=1
- for %%x in (*.xml) do (
- for /f "tokens=* delims=" %%i in (%%x) do (
- set "var=%%i"
- set "var=!var:300=100!"
- echo.!var!>>!a!.xml.love
- )
- set /a a=!a!+1
- )
hxuan?表ー: 2006-11-24 13:33
Then talk about blank lines. The post on floor 1:
This script is to replace 300 with 100 in the xml text in a certain directory. The script can modify correctly, but if there is a blank line (such as only one carriage return, or there are other space characters, tab characters), the blank line will be replaced with "300=100", which is very depressed. Please ask for a solution! Thank you!
It seems that it's not that blank lines are replaced with "300=100", but space lines and tab lines. Blank lines have no output.
Execute the following code:
- @echo off
- setlocal enabledelayedexpansion
- set a=1
- for /f "tokens=* delims=" %%i in (a.xml) do (
- echo --!a!--%%i--
- set /a a+=1
- )
- pause
hxuan?表ー: 2006-11-24 14:10
The result is that no matter how the options of FOR are set, blank lines are not output. In fact, blank lines are not read and are directly skipped. So the code on floor 4 is also wrong, and blank lines are still not output.
I am also a newbie. Please give pointers if what I said is wrong. Also, if any expert can solve the problem of blank lines, I also want to ask.
[
Last edited by hxuan999 on 2006-11-24 at 03:21 PM ]