這篇文章給大家分享的是有關(guān)批處理如何按要求將字符串分段輸出的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
堅(jiān)守“ 做人真誠(chéng) · 做事靠譜 · 口碑至上 · 高效敬業(yè) ”的價(jià)值觀,專業(yè)網(wǎng)站建設(shè)服務(wù)10余年為成都成都酒樓設(shè)計(jì)小微創(chuàng)業(yè)公司專業(yè)提供企業(yè)網(wǎng)站制作營(yíng)銷網(wǎng)站建設(shè)商城網(wǎng)站建設(shè)手機(jī)網(wǎng)站建設(shè)小程序網(wǎng)站建設(shè)網(wǎng)站改版,從內(nèi)容策劃、視覺設(shè)計(jì)、底層架構(gòu)、網(wǎng)頁(yè)布局、功能開發(fā)迭代于一體的高端網(wǎng)站建設(shè)服務(wù)。一、要求用批處理隨機(jī)輸出200個(gè)字符到1.txt中的一行,內(nèi)容類同如下:
代碼:
xh55q3ma+remgofm54sevhrna4g5r8pl9cjardezqjwj3m8itamh0a4itzd6jz8cmrfmibmhr0wmccyb8qnp2qh5rvlwff6yr2ez4eo063u6viy7ppw+nzxaxe8vrm190eei_0dwx5e2kxbds-ae6e96c9_i9glw8mz+uf6uienx9od8bktfnjlwlqu-e1rcj33_+4bz
二、要求用批處理將1.txt中的內(nèi)容按10個(gè)字符為一段輸出如下面兩種形式:
在一行內(nèi)輸出:
代碼:
xh55q3ma+r emgofm54se vhrna4g5r8 pl9cjardez qjwj3m8ita mh0a4itzd6 jz8cmrfmib mhr
0wmccyb 8qnp2qh5rv lwff6yr2ez 4eo063u6vi y7ppw+nzxa xe8vrm190e ei_0dwx5e2 kxbds-
ae6e 96c9_i9glw 8mz+uf6uie nx9od8bktf njlwlqu-e1 rcj33_+4bz
分行輸出:
代碼:
xh55q3ma+r
emgofm54se
vhrna4g5r8
pl9cjardez
qjwj3m8ita
mh0a4itzd6
jz8cmrfmib
mhr0wmccyb
8qnp2qh5rv
lwff6yr2ez
4eo063u6vi
y7ppw+nzxa
xe8vrm190e
ei_0dwx5e2
kxbds-ae6e
96c9_i9glw
8mz+uf6uie
nx9od8bktf
njlwlqu-e1
rcj33_+4bz
----------------------------------------------------------------------------------------------------------------------------------------------------
要求:代碼高效、通用、簡(jiǎn)潔、不產(chǎn)生臨時(shí)文件
ps:請(qǐng)老手們將本題留給新手完成
more:
代碼如下:
@echo off
Setlocal Enabledelayedexpansion
set "str=abcdefghijklmnopqrstuvwxyz1234567890+-_"
for /l %%a in (1 1 200) do (
set /a "m=!random!%%39"
call set "var1=%%var1%%%%str:~!m!,1%%"
)
set "var=%var1%"
for /l %%a in (1 1 20) do (
set "var2=!var:~,10!"
set /p =!var2!
)
echo.&echo.&set "var=%var1%"
for /l %%a in (1 1 20) do (
set "var2=!var:~,10!"
echo.!var2!
set "var=!var:~10!"
)
pause>nul
shqf:
代碼如下:
@echo off
set /p str=<1.txt
set /p select=1.一行內(nèi)分節(jié)顯示 2.分行顯示(請(qǐng)選擇1-2):
if %select% equ 2 goto fh
:fj
set /p=%str:~,10%
pause>nul&goto end
:fh
echo %str:~,10%
if not "%str:~10%"=="" (set str=%str:~10%&goto fh)
pause>nul
terse:
代碼如下:
@echo off&Setlocal Enabledelayedexpansion
set "var=abcdefghijklmnopqrstuvwxyz1234567890+-_"
for /l %%i in (1 1 200) do set /a "m=!random!%%39"&call set str=!str!%%var:~!m!,1%%
>1.txt echo %str%
for /l %%i in (1 1 20) do set /p=!str:~,10!
for /l %%i in (1 1 20) do echo.!%%i!
pause>nul
pusofalse:
代碼如下:
@echo off&setlocal enabledelayedexpansion
set var=abcdefghijklmnopqrstuvwxyz0123456789+-_
for /l %%a in (1 1 200) do (
set/a n=!random!%%39
call,set a=!a!%%var:~!n!,1%%
)
echo %a%&pause>nul&echo.
:lp
for /l %%i in (0 10 190) do if not defined b (set/p=!a:~%%i,10!
pause
inittab:
代碼如下:
@echo off&setlocal enabledelayedexpansion
set "str=1234567890abcdefghijklmnopqrstuvwxyz@#$_+-"
for /l %%i in (0,1,199) do (
set/a ran=!random!%%42&call set "st=!st!%%str:~!ran!,1%%"
)
echo 整行輸出: !st!&echo.&echo 分列輸出:
for /l %%j in (0,10,190) do (
set /a m=%%j
call set "st1=!st1!%%st:~!m!,10%% "
call echo %%st:~!m!,10%%
)
echo.&echo 分段輸出: !st1!
pause
netbenton:
代碼如下:
@echo off&setlocal enabledelayedexpansion
set "str=1234567890abcdefghijklmnopqrstuvwxyz@#$_+-"
for /l %%i in (0,1,199) do set/a ran=!random!%%42&for %%a in (!ran!) do set "st=!st!!str:~%%a,1!"
echo 整行輸出: !st!&echo.&echo 分列輸出:
for /l %%j in (0,10,190) do echo !st:~%%j,10!&set "st1=!st1!!st:~%%j,10! "
echo.&echo 分段輸出: !st1!
pause
bathman:
代碼如下:
@echo off
rem 隨機(jī)生成200個(gè)字符
set "var=abcdefghijklnmopqrstuvwxyz0123456789+_/-"
:begin
set /a a=%random%%%40,n+=1
call,set "str=%str%%%var:~%a%,1%%"
if %n% neq 200 goto begin
rem 在一行內(nèi)分段輸出
:lp
set /a m+=1
set /p=%str:~,10%
if defined str goto lp
rem 分行輸出分段后字符
echo.&echo.&for /l %%i in (1,1,%m%) do call,echo %%_%%i%%
pause>nul
感謝各位的閱讀!關(guān)于“批處理如何按要求將字符串分段輸出”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!