华域联盟 DOS/BAT 处理判断字符串长度的代码

处理判断字符串长度的代码

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

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

习题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


您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » 处理判断字符串长度的代码

转载请保留出处和原文链接:https://www.cnhackhy.com/16673.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部