處理判斷字符串長(zhǎng)度的代碼
更新時(shí)間:2010年10月11日 13:36:45 作者:
一題多解,可別只用重定向文本 那個(gè)方法哈。
呵呵大家也看到題目--基礎(chǔ)練習(xí)。我不會(huì)出的太難的,這道題的思路應(yīng)該會(huì)比較多的
不過(guò)我也還沒(méi)開始做,希望大家積極參與哦。(最慘的就是只能加別人兩分,郁悶)
習(xí)題1.1 字符串長(zhǎng)度不超過(guò)80。不含特殊字符
例 i like the bathome,because here is the batch of the world.
1.2 字符串長(zhǎng)度小于255,含有特殊字符,試求其長(zhǎng)度。
例 %%a%%!ver!&^^^ ^*~ are you o k ?" : \ / ` ` verfdxcweippo opj x ds gw !%%
一般的,先求1.1的題目。看誰(shuí)的代碼靈活、簡(jiǎn)潔、思路清晰。然后再做1.2
(汗。中文不用考慮……)
其實(shí)我也是想征集一個(gè)比較好的辦法……估計(jì)如果有中文的話?;蛟S可以重定向到文本然后再判斷字節(jié)吧。我猜可以的。
最后:一題多解,可別只用 重定向文本 那個(gè)方法哈。
523066680:
@echo off
echo,i like the bathome,because here is the batch of the world.>x.x
for /f "tokens=*" %%a in ('dir x.x /-c ^|find " 字節(jié)" ^|find /v ":"') do (
for /f "tokens=3" %%b in ('echo,%%a') do (
set /a n=%%b-2
call echo %%n%%
del x.x
)
)
pause>nul
shqf:
::%%a%%!ver!&^^^ ^*~ are you o k ?" : \ / ` ` verfdxcweippo opj x ds gw !%%
@echo off&setlocal enabledelayedexpansion
set /p str=<%0
for /l %%a in (1,1,255) do (set str=!str:~1!&if "!str!"=="" (set /a totle=%%a-2&echo !totle!&goto end))
:end
pause
terse:
@echo off&setlocal enabledelayedexpansion
set/p str=Type :
for /l %%i in (1,1,10000) do if "!str:~%%i,1!"=="" echo %%i&pause&exit
不過(guò)我也還沒(méi)開始做,希望大家積極參與哦。(最慘的就是只能加別人兩分,郁悶)
習(xí)題1.1 字符串長(zhǎng)度不超過(guò)80。不含特殊字符
例 i like the bathome,because here is the batch of the world.
1.2 字符串長(zhǎng)度小于255,含有特殊字符,試求其長(zhǎng)度。
例 %%a%%!ver!&^^^ ^*~ are you o k ?" : \ / ` ` verfdxcweippo opj x ds gw !%%
一般的,先求1.1的題目。看誰(shuí)的代碼靈活、簡(jiǎn)潔、思路清晰。然后再做1.2
(汗。中文不用考慮……)
其實(shí)我也是想征集一個(gè)比較好的辦法……估計(jì)如果有中文的話?;蛟S可以重定向到文本然后再判斷字節(jié)吧。我猜可以的。
最后:一題多解,可別只用 重定向文本 那個(gè)方法哈。
523066680:
復(fù)制代碼 代碼如下:
@echo off
echo,i like the bathome,because here is the batch of the world.>x.x
for /f "tokens=*" %%a in ('dir x.x /-c ^|find " 字節(jié)" ^|find /v ":"') do (
for /f "tokens=3" %%b in ('echo,%%a') do (
set /a n=%%b-2
call echo %%n%%
del x.x
)
)
pause>nul
shqf:
復(fù)制代碼 代碼如下:
::%%a%%!ver!&^^^ ^*~ are you o k ?" : \ / ` ` verfdxcweippo opj x ds gw !%%
@echo off&setlocal enabledelayedexpansion
set /p str=<%0
for /l %%a in (1,1,255) do (set str=!str:~1!&if "!str!"=="" (set /a totle=%%a-2&echo !totle!&goto end))
:end
pause
terse:
復(fù)制代碼 代碼如下:
@echo off&setlocal enabledelayedexpansion
set/p str=Type :
for /l %%i in (1,1,10000) do if "!str:~%%i,1!"=="" echo %%i&pause&exit
相關(guān)文章
將批處理文件注冊(cè)成服務(wù)在系統(tǒng)啟動(dòng)的時(shí)候自動(dòng)調(diào)用
如何將批處理文件注冊(cè)成服務(wù),在系統(tǒng)啟動(dòng)的時(shí)候就自動(dòng)調(diào)用startagent.bat腳本,下面是具體的實(shí)現(xiàn)過(guò)程,需要的朋友可以參考下2014-04-04學(xué)會(huì)批處理,用心學(xué)很容易!另一不錯(cuò)的見解
學(xué)會(huì)批處理,用心學(xué)很容易!另一不錯(cuò)的見解...2007-03-03