China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 10:49
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [fixed] Question about replacing specified content in a file View 762 Replies 9
Original Poster Posted 2009-02-26 01:43 ·  中国 吉林 四平 联通
新手上路
Credits 11
Posts 8
Joined 2009-02-21 12:09
17-year member
UID 139448
Gender Male
Status Offline
Source file contents:
Q(0)="If you don't equip a magic treasure, you won't be able to use it?"
A(0)="Combat skill"
Q(1)="At which NPC can you use a dim inner core to exchange for the mount summoning talisman you want?"
A(1)="Shitang County Demon Sealer"
Q(2)="Which of the following statements is correct?"
A(2)="If a red-name attacks a white-name, criminal points will increase"
Q(3)="What professions' magic treasures can be obtained by raising government prestige?"
A(3)="Warrior, Ranger"
Q(4)="Which shortcut key opens the etiquette action interface? "
A(4)="Key P"
……
……
Replace with:
@@If you don't equip a magic treasure, you won't be able to use it?
Combat skill
@@At which NPC can you use a dim inner core to exchange for the mount summoning talisman you want?
Shitang County Demon Sealer
@@Which of the following statements is correct?
If a red-name attacks a white-name, criminal points will increase
@@What professions' magic treasures can be obtained by raising government prestige?
Warrior
Ranger
@@Which shortcut key opens the etiquette action interface?
Key P


The problem seems quite complicated, and besides, I don't really understand batch files. Thanks a lot for everyone's help.
Additional note: the filename is 1.txt
I tested both people's versions and they don't work
Also, there are numbers in the questions here, and those numbers can't be deleted.

[ Last edited by zuoyuanchun on 2009-2-27 at 04:30 ]
Floor 2 Posted 2009-02-26 02:34 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
@echo off&setlocal enabledelayedexpansion
for /f "tokens=1,* delims==" %%a in (source file) do set str=%%a&call :sub!str:~0,1! %%~b
goto :eof
:subQ
echo @@%*
goto :eof

:subA
echo.%1
shift
if "%1"=="" goto :eof
goto :subA

[ Last edited by netbenton on 2009-2-26 at 12:12 ]
精简
=> 个人网志
Floor 3 Posted 2009-02-26 05:25 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Floor 4 Posted 2009-02-26 08:49 ·  中国 吉林 四平 联通
新手上路
Credits 11
Posts 8
Joined 2009-02-21 12:09
17-year member
UID 139448
Gender Male
Status Offline
http://upload.cn-dos.net/img/1331.txt
I've already uploaded it, so everyone can just help write a batch file to process it directly, thanks
Floor 5 Posted 2009-02-26 14:11 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
精简
=> 个人网志
Floor 6 Posted 2009-02-26 22:51 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
zuoyuanchun +1 2009-02-27 04:25
Floor 7 Posted 2009-02-27 01:22 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
zuoyuanchun +1 2009-02-27 04:26
Floor 8 Posted 2009-02-27 04:30 ·  中国 吉林 四平 联通
新手上路
Credits 11
Posts 8
Joined 2009-02-21 12:09
17-year member
UID 139448
Gender Male
Status Offline
Originally posted by moniuming at 2009-2-26 22:51:
@echo off
setlocal enabledelayedexpansion
set "srcfl=1.txt"
for /f "tokens=1,* delims==" %%a in (%srcfl%) do (
set "str=%%a"
if /i "!str:~,1!" ...


This one is not bad, at least I can understand what it means. Learned something.
Floor 9 Posted 2009-02-27 04:32 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
简单!简单!再简单!
Floor 10 Posted 2009-02-27 09:06 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
...
@@At which NPC can you use a dim inner core to exchange for the mount summoning talisman you want?
Shitang County Demon Sealer
@@Which of the following statements is correct?
If a red-name attacks a white-name, criminal points will increase
@@What professions' magic treasures can be obtained by raising government prestige?
Warrior
Ranger

@@Which shortcut key opens the etiquette action interface?
Key P
...



Question for the OP: should the red part here be split onto separate lines?
精简
=> 个人网志
Forum Jump: