处理判断字符串长度的代码
处理判断字符串长度的代码
发布时间:2016-12-28 来源:查字典编辑
摘要:呵呵大家也看到题目--基础练习。我不会出的太难的,这道题的思路应该会比较多的不过我也还没开始做,希望大家积极参与哦。(最惨的就是只能加别人两...

呵呵大家也看到题目--基础练习。我不会出的太难的,这道题的思路应该会比较多的

不过我也还没开始做,希望大家积极参与哦。(最惨的就是只能加别人两分,郁闷)

习题1.1 字符串长度不超过80。不含特殊字符

例 i like the bathome,because here is the batch of the world.

1.2 字符串长度小于255,含有特殊字符,试求其长度。

例 %%a%%!ver!&^^^ ^*~ are you o k ?" : / ` ` verfdxcweippo opj x ds gw !%%

一般的,先求1.1的题目。看谁的代码灵活、简洁、思路清晰。然后再做1.2

(汗。中文不用考虑……)

其实我也是想征集一个比较好的办法……估计如果有中文的话。或许可以重定向到文本然后再判断字节吧。我猜可以的。

最后:一题多解,可别只用 重定向文本 那个方法哈。

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 " 字节" ^|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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新DOS/BAT学习
热门DOS/BAT学习
脚本专栏子分类