|
|
本帖最后由 canyuexiaolang 于 2012-5-20 09:22 编辑
搜了一下batman给的解貌似很麻烦。不知是不是里面还需要事先其他功能的问题。
嗯,批处理替换星号的话set无解,就是加上转义符也不行。sed貌似可以把,但是我不喜欢第三方
百度知道搜索看见用for的,但是很局限。
- @echo off
- setlocal enabledelayedexpansion
- set "str=asfasfas**asfadna!@#$%*&^#$%^*^^%^@^&*#%&**"
- for /f "tokens=1,2,3,4" %%i in ("!str!") do echo %%i%%j%%k%%l
- pause
复制代码
的确很麻烦。
试了一下call :lable的递归。(姑且叫做递归。。。)
- @echo off
- set "str=asfasfas**asfadna!@#$%*&^#$%^*^^%^@^&*#%&**"
- for /f "delims=" %%i in ("!str!") do (
- setlocal enabledelayedexpansion
- call :replace "%%i"
- echo !lines!
- endlocal
- )
- pause & exit
- :replace
- for /f " tokens=1* delims=*" %%x in ("%~1") do set "lines=!lines!%%x" & call :replace "%%y"
- rem 注意这个callcallcall。因为for里面没神马东西的时候for/f不会执行,所以不用加条件限制
- rem 其实这个“因为for里面没神马东西的时候for/f不会执行”很是令人困恼啊,不过这次利用了
- goto :eof
复制代码
额。。发一下。。让大家知道这样用真的很bt。。顺便让大家知道不用第三方也能替换*。。。(只是清空!!!) |
|