|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
很容易了,把echo 变量 改为echo 到文件就行了
It's very easy. Just change "echo variable" to "echo to the file".
|
|
2007-9-24 13:00 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-24 01:00 PM:
很容易了,把echo 变量 改为echo 到文件就行了
呵呵,谢谢你.我明白了.
Originally posted by yoyodos at 2007-9-24 01:00 PM:
It's easy, just change echo variable to echo to file.
Hehe, thank you. I understand.
|
|
2007-9-24 13:02 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
|
2007-9-24 13:08 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
我也贴一个,哈哈
@echo off
setlocal enabledelayedexpansion
cd.>tmp.txt
set /a x=0
for /f "tokens=1 delims=姓名," %%r in (ab.txt) do echo %%r>>tmp.txt
for /f "delims=" %%a in (ab.txt) do (
set /a x+=1
set str=%%a
for /f "tokens=1* delims=:" %%h in ('findstr /n "." tmp.txt') do (
set n1=%%h
if !n1!==!x! (
set replaced=%%i
)
)
for /f "tokens=1* delims=:" %%m in ('findstr /n "." cd.txt') do (
set n2=%%m
if !n2!==!x! (
set new="%%n"
)
)
call :replace
)
del /q tmp.txt
pause
:replace
set str=!str:%replaced%=%new%!
echo !str!
Last edited by yoyodos on 2007-9-24 at 03:02 PM ]
I also post one, haha
@echo off
setlocal enabledelayedexpansion
cd.>tmp.txt
set /a x=0
for /f "tokens=1 delims=姓名," %%r in (ab.txt) do echo %%r>>tmp.txt
for /f "delims=" %%a in (ab.txt) do (
set /a x+=1
set str=%%a
for /f "tokens=1* delims=:" %%h in ('findstr /n "." tmp.txt') do (
set n1=%%h
if !n1!==!x! (
set replaced=%%i
)
)
for /f "delims=" %%m in ('findstr /n "." cd.txt') do (
set n2=%%m
if !n2!==!x! (
set new="%%n"
)
)
call :replace
)
del /q tmp.txt
pause
:replace
set str=!str:%replaced%=%new%!
echo !str!
Last edited by yoyodos on 2007-9-24 at 03:02 PM ]
|
|
2007-9-24 15:01 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-24 03:01 PM:
我也贴一个,哈哈
@echo off
setlocal enabledelayedexpansion
cd.>tmp.txt
set /a x=0
for /f "tokens=1 delims=姓名," %%r in (ab.txt) do echo %%r>>tmp.txt
fo ...
总体来说主要有2个关键点值得学习
1、是 "tokens=1 delims=“的用法,这一点很多时候非常容易弄错
2、是变量替换提取
如果ab.txt的内容由原来的:
姓名"张三",ID'102' ,tel'0102211',0,25,11
姓名"李似答",ID'102' ,tel'0202211',0,25,11
姓名"王二",ID'102' ,tel'01023311',0,25,11
........
变成如下:
abcd rster_www_er 姓 名 "张三",ID'102' ,tel'0102211',0,25,11
abcd rster_www_er 姓 名 "李似答",ID'102' ,tel'0202211',0,25,11
abcd rster_www_er 姓 名 "王二",ID'102' ,tel'01023311',0,25,11
....
那么以上的参考答案代码都需要做适当的修改。
从这里可以知道,如果是编辑一个通用性强的代码,最好能够采用模糊查找定位的方法,比如本例,即使ab.txt文件每行的长度和里面其它内容变化,只要含有
这样的字段,就可以查到,并替换.
请问是否可以实现?
Originally posted by yoyodos at 2007-9-24 03:01 PM:
I'll post one too, haha
@echo off
setlocal enabledelayedexpansion
cd.>tmp.txt
set /a x=0
for /f "tokens=1 delims=姓名," %%r in (ab.txt) do echo %%r>>tmp.txt
fo ...
Generally speaking, there are mainly 2 key points worthy of learning
1. The usage of "tokens=1 delims=", this point is very easy to get wrong many times
2. Variable replacement and extraction
If the content of ab.txt is changed from the original:
Name "Zhang San", ID '102', tel '0102211', 0, 25, 11
Name "Li Sida", ID '102', tel '0202211', 0, 25, 11
Name "Wang Er", ID '102', tel '01023311', 0, 25, 11
........
To the following:
abcd rster_www_er Name "Zhang San", ID '102', tel '0102211', 0, 25, 11
abcd rster_www_er Name "Li Sida", ID '102', tel '0202211', 0, 25, 11
abcd rster_www_er Name "Wang Er", ID '102', tel '01023311', 0, 25, 11
....
Then the above reference answer codes all need to be appropriately modified.
From this, it can be known that if you are editing a highly universal code, it is best to use the method of fuzzy search and positioning. For example, in this case, even if the length of each line of the ab.txt file and other contents change, as long as there is a field like , it can be found and replaced.
Can this be achieved?
|
|
2007-9-24 15:51 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
不太明白你的意思,
思路就是将每一行字符串的 “姓名” 替换成 "abcd rster_www_er 姓 名"
是不是就可以呢?
哈哈
I don't quite understand what you mean.
The idea is to replace "姓名" in each line of the string with "abcd rster_www_er 姓 名", right?
Hahaha
|
|
2007-9-24 16:10 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-24 04:10 PM:
不太明白你的意思,
思路就是将每一行字符串的 “姓名” 替换成 "abcd rster_www_er 姓 名"
是不是就可以呢?
哈哈
不是的,我的意思是作为通用性强的搜索语句,采用模糊定位查找,比采用按照分割符号来查找的方式更加实用。
比如最开始的ab.txt文件里的内容:
姓名"张三",ID'102' ,tel'0102211',0,25,11
姓名"李似答",ID'102' ,tel'0202211',0,25,11
姓名"王二",ID'102' ,tel'01023311',0,25,11
这是非常工整的
要是不工整的,变为:
abcd rster_www_er 姓 名 "张三",ID'102' ,tel'0102211',0,25,11
abcd ,er 姓 名 "李似答",ID'102' ,tel'0202211',0,25,11
abcd rster,www,r 姓 名 "王二",ID'102' ,tel'01023311',0,25,11
这样的格式,严格以分割符查找的设计思路,几乎用不成,而采用模糊查找才能实现。
总的来说就是无论你每行文字变成什么样,在每行任何不同位置变换,都能实现替换功能。
Last edited by 123cainiao on 2007-9-24 at 04:43 PM ]
Originally posted by yoyodos at 2007-9-24 04:10 PM:
I don't quite understand what you mean.
The idea is to replace "Name" in each line of the string with "abcd rster_www_er 姓 名".
Is that okay?
Haha
No, what I mean is that as a highly versatile search statement, using fuzzy positioning to find is more practical than using the method of finding according to the delimiter.
For example, the content in the original ab.txt file:
Name "Zhang San", ID '102', tel '0102211', 0, 25, 11
Name "Li Sida", ID '102', tel '0202211', 0, 25, 11
Name "Wang Er", ID '102', tel '01023311', 0, 25, 11
This is very neat.
If it is not neat, it becomes:
abcd rster_www_er 姓 名 "Zhang San", ID '102', tel '0102211', 0, 25, 11
abcd, er 姓 名 "Li Sida", ID '102', tel '0202211', 0, 25, 11
abcd rster, www, r 姓 名 "Wang Er", ID '102', tel '01023311', 0, 25, 11
With such a format, the design idea of strictly finding according to the delimiter is almost unusable, and only fuzzy finding can be implemented.
In general, no matter how each line of text becomes, can be replaced in any different position in each line.
Last edited by 123cainiao on 2007-9-24 at 04:43 PM ]
|
|
2007-9-24 16:40 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
晕,以姓名作分隔符不就行了吗
在delims=后面写姓名,姓 名,姓 名。。。。就能得到后面的名字了啊
Oh, just use the name as the delimiter, right? Write the names after delims=, like 姓 名, 姓 名... and you can get the following names.
|
|
2007-9-24 17:18 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-24 05:18 PM:
晕,以姓名作分隔符不就行了吗
在delims=后面写姓名,姓 名,姓 名。。。。就能得到后面的名字了啊
谢谢你回答,经过反复测试,做了适当调整,可以了。
你的代码适用性能是非常好的。再次感谢!
Originally posted by yoyodos at 2007-9-24 05:18 PM:
Oh, just use the name as a delimiter.
Write the name after delims=, such as 姓 名, 姓 名..., and you can get the subsequent names.
Thank you for your answer. After repeated testing and appropriate adjustments, it works.
Your code has very good applicability. Thanks again!
|
|
2007-9-24 18:49 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
我也来一段学习
@echo off
setlocal enabledelayedexpansion
set mn=0
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%i%%j
set /a mn+=1
for /f "tokens=1* delims=:" %%a in ('findstr /n .* cd.txt') do (
if !mn! EQU %%a set data=!data:%%i=姓名"%%b",!
)
echo !data!>>c12.txt
)
pause
I also come to learn
@echo off
setlocal enabledelayedexpansion
set mn=0
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%i%%j
set /a mn+=1
for /f "tokens=1* delims=:" %%a in ('findstr /n .* cd.txt') do (
if !mn! EQU %%a set data=!data:%%i=姓名"%%b",!
)
echo !data!>>c12.txt
)
pause
|
|
2007-9-24 19:13 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2007-9-24 07:13 PM:
我也来一段学习
@echo off
setlocal enabledelayedexpansion
set mn=0
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%i%%j
set /a mn+=1
for ...
以上所有回复的参考答案中terse给的适应性能最强,可以不加修改完全适应通用性文件的查找替换,只许需要把 姓名 字段替换为你要查找的即可.
谢谢terse
Originally posted by terse at 2007-9-24 07:13 PM:
I'll also contribute a section for learning
@echo off
setlocal enabledelayedexpansion
set mn=0
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%i%%j
set /a mn+=1
for ...
Among all the previous responses, terse's one has the strongest adaptability and can be fully adapted to the search and replacement of general-purpose files without modification. Only the "name" field needs to be replaced with what you want to search for.
Thank you, terse
|
|
2007-9-25 13:25 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 27 楼』:
问题的延伸,看看下面的情况会用到很多
使用 LLM 解释/回答一下
如果把问题延伸,比如ab.txt文件只有这么一行
姓名"张三",ID'102' ,tel'0102211',0,25,11
现在cd.txt文件还是不变:
赵括
王彬
李铃
。。。。。
可否做到从ab.txt文件里替换第一行后的姓名后,直接可以复制这种格式,生成一个完全和cd.txt文件行数一致的文件ef.txt:
姓名"赵括",ID'102' ,tel'0102211',0,25,11
姓名"王彬",ID'102' ,tel'0102211',0,25,11
姓名"李铃",ID'102' ,tel'0102211',0,25,11
........
这里问题就不单单是对等行替换了,需要涉及复制,想来还是会复杂一些。
If we extend the problem, for example, the ab.txt file has only this line:
Name "Zhang San", ID '102', tel '0102211', 0, 25, 11
Now the cd.txt file remains unchanged:
Zhao Kuo
Wang Bin
Li Ling
......
Can we replace the name after the first line in the ab.txt file and then directly copy this format to generate a file ef.txt that has exactly the same number of lines as the cd.txt file:
Name "Zhao Kuo", ID '102', tel '0102211', 0, 25, 11
Name "Wang Bin", ID '102', tel '0102211', 0, 25, 11
Name "Li Ling", ID '102', tel '0102211', 0, 25, 11
........
Here the problem is not just about replacing corresponding lines, but also involves copying, which I think will be more complicated.
|
|
2007-9-25 13:43 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%j
)
for /f "tokens=1* delims=:" %%a in (cd.txt) do (
>>c12.txt echo 姓名"%%a",!data!
)
pause
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims=," %%i in (ab.txt) do (
set data=%%j
)
for /f "tokens=1* delims=:" %%a in (cd.txt) do (
>>c12.txt echo 姓名"%%a",!data!
)
pause
|
|
2007-9-25 14:23 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
terse回答的很好呀,哈,123cainiao还有问题没??我也练练
Terse answer is very good, ha, does 123cainiao still have questions? I also practice
|
|
2007-9-25 14:29 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-25 02:29 PM:
terse回答的很好呀,哈,123cainiao还有问题没??我也练练
呵呵,谢谢各位回答,不同的程序表达方式,达到相同的目的,值得好好研究.
顺祝大家中秋快乐,合家幸福!
Originally posted by yoyodos at 2007-9-25 02:29 PM:
Terse's answer is very good, haha, does 123cainiao still have any questions?? I'll also practice
Hehe, thank you all for your answers. Different program expressions achieve the same goal, which is worth studying carefully.
Best wishes to everyone for a happy Mid-Autumn Festival and a happy family!
|
|
2007-9-25 16:37 |
|
|