[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

【练习-018】按要求整理并改写文本

出题目的:
        掌握字符截取技巧
        掌握学符替换技巧
        掌握改写文本技巧        
解题要求:
        代码通用、高效
        尽量简洁
        不生成临时文件
加分规则:
         思路独特基准分5分
        代码高效、通用基准分4分
        技巧高超基准分3分
        代码简洁基准分2分
        完美代码加分15分           
题目如下:
  有文本a.txt
  1. Network vertically: In the research phase of your job hunt,talk to
  2. people who are on a level above you in your desired industry. They'll
  3. have some insights that people at your own level won't have,and will be
  4. in a good position to hire you or recommend you to be hired. Keep your
  5. spirits up. Looking for a job is one of the toughest things you will
  6. ever have to do. Maintain your confidence,stay persistent,and think
  7. positively,and eventually you will get a job that suits you.
复制代码
1 要求通过批处理将文本中的you全替换成me并输出,但your不能变
2 要求通过批处理将文本整理成如下格式(遇:号和.号换行并在行首空两格),并生成文本b.txt:
  1. Network vertically:
  2.   In the research phase of your job hunt,talk to people who are on a level abov
  3. e me in your desired industry.
  4.   They'll have some insights that people at your own level won't have,and will
  5. be in a good position to hire me or recommend me to be hired.
  6.   Keep your spirits up.
  7.   Looking for a job is one of the toughest things me will ever have to do.
  8.   Maintain your confidence,stay persistent,and think positively,and eventuall
  9. y me will get a job that suits me.
复制代码
3 要求将文本b.txt中的Looking for a job is one of the toughest things me will ever have to do.
这句改写成bathomework is a nice job,其它的不变。
解题限制:
  高手请暂做旁观,请新手老手解答。
补充两点:
       1 a.txt中只有一行
       2 解题中不使用第三方工具(并不是提倡不使用第三方)

[ 本帖最后由 batman 于 2008-8-30 13:00 编辑 ]
***共同提高***

楼上的出现了书写错误吧:@echo,off
***共同提高***

TOP

原帖由 wangwei4106 于 2008-8-30 11:04 发表
2楼代码有误,至少最后一个you.就替换不了!
这样应该就可以了!
@echo off&setlocal enabledelayedexpansion
for /f "tokens=* delims= " %%i in (a.txt) do (
set aa=%%i
set aa=!aa:you=me!
set aa=!aa:mer ...

为什么要tokens=* delims= 呢?
***共同提高***

TOP

提示:考虑问题复杂化,解决问题简洁化
***共同提高***

TOP

返回列表