| 
 
namejm 
荣誉版主
 
        batch fan
  
 
积分 5226 
发帖 1737 
注册 2006-3-10 来自 成都 
状态 离线
 | 
『楼 主』:
 如何统计某个字符串在文本中出现的次数?
 
使用 LLM 解释/回答一下
  
  比如有个文本文件,里面有几行内容,比如: 
  1,2,3,4 
      7,8,9,10 
      …… 
  如何统计其中逗号的个数? 
For example, there is a text file with several lines of content, such as: 
1,2,3,4 
7,8,9,10 
…… 
How to count the number of commas in it? 
    
 
  
 |   
 | 
  2006-6-14 19:39 | 
  
 | 
 | 
 
bagpipe 
银牌会员
 
      DOS联盟捡破烂的
  
 
积分 1144 
发帖 425 
注册 2005-10-20 来自 北京 
状态 离线
 | 
『第 2 楼』:
 
 
使用 LLM 解释/回答一下
  
其实对于此类题目我并没有很好的办法,本人觉得局限性也很大,没有找到很好的办法解决,不过楼主可以试试以下代码: 
 
@echo off 
setlocal enabledelayedexpansion 
set a= 
for /f "delims=" %%a in (要检索的文件.txt) do set a=!a!%%a 
:back 
set /a b+=1 
set a=%a:*,=% 
if "%a%"=="这里是最后一个逗号后面内容" goto end 
goto back 
 
:end 
echo 共有 %b% 个逗号 
In fact, I don't have a very good way for this kind of question. I think the limitations are also very big, and I haven't found a good way to solve it. But the landlord can try the following code: 
 
@echo off 
setlocal enabledelayedexpansion 
set a= 
for /f "delims=" %%a in (要检索的文件.txt) do set a=!a!%%a 
:back 
set /a b+=1 
set a=%a:*,=% 
if "%a%"=="这里是最后一个逗号后面内容" goto end 
goto back 
 
:end 
echo There are %b% commas 
    
 
  
 |   
 | 
  2006-6-15 10:53 | 
  
 | 
 | 
 
piziliu2004 
中级用户
 
    过度热情
  
 
积分 321 
发帖 139 
注册 2006-3-21 
状态 离线
 | 
『第 3 楼』:
 
 
使用 LLM 解释/回答一下
  
to: bAGPIPE   
 
set a=%a:*,=%是什麼意思.? 
to: bAGPIPE   
 
What does set a=%a:*,=% mean? 
    
 
  
 |   
 | 
  2006-6-15 13:50 | 
  
 | 
 | 
 
kcdsw 
中级用户
 
   
 
  
  
积分 404 
发帖 179 
注册 2006-3-30 
状态 离线
 | 
『第 4 楼』:
 
 
使用 LLM 解释/回答一下
  
看帮助 
 
set 变量名=%变量:1=2% 
这个意思是说 用=后边的2替换前边的1 
Look at help 
 
set 变量名=%变量:1=2% 
This means to replace 1 in front with 2 after =. 
    
 
  
 |   
 | 
  2006-6-15 15:23 | 
  
 | 
 | 
 
namejm 
荣誉版主
 
        batch fan
  
 
积分 5226 
发帖 1737 
注册 2006-3-10 来自 成都 
状态 离线
 | 
『第 5 楼』:
 
 
使用 LLM 解释/回答一下
  
  感谢bagpipe,在你的代码基础上,我稍加改造就能用了。 
  ——你说的局限性应该是if "%a%"=="这里是最后一个逗号后面内容" goto end这句要手工输入内容吧? 
Thanks to bagpipe, I can use it with a little modification based on your code.  
——The limitation you mentioned should be that the content after the last comma in "if "%a%"=="here is the content after the last comma" goto end" needs to be entered manually, right? 
    
 
  
 |   
 | 
  2006-6-15 16:07 | 
  
 | 
 | 
 
bagpipe 
银牌会员
 
      DOS联盟捡破烂的
  
 
积分 1144 
发帖 425 
注册 2005-10-20 来自 北京 
状态 离线
 | 
『第 6 楼』:
 
 
使用 LLM 解释/回答一下
  
我所说的局限性并非namejm兄所说,其实“最后一个逗号后面的内容”我可以得到,我所说的局限性就是因为你把文件中所有字符都赋值给一个变量,而这个变量最大能够承受多少字符,如果最后逗号后面没有字符,这种情况就不成了 
The limitations I mentioned are not what Brother namejm said. In fact, I can get the content after the last comma. The limitation I mentioned is because you assign all the characters in the file to a variable, and then how many characters this variable can bear at most. If there is no content after the last comma, this situation will not be the case. 
    
 
  
 |   
 | 
  2006-6-16 08:30 | 
  
 |