In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to calculate the length of a string in batches". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "how to calculate the length of a string in batches".
The code is as follows:
@ echo off & setlocal EnableDelayedExpansion
:: calculate the length of the string
::
::
: began
Set mystr=
Set / p mystr= enter the string to calculate the length (directly enter exit):
If not defined mystr goto: eof
For / l% I in do if "! mystr:~%%i,1!" = "" set strlen=%%i & & goto: _ endfor
: _ endfor
:: echo string: "% mystr%"
Echo length:% strlen%
Set strlen=
Goto began
The disadvantage of this scheme is that when the length of the string exceeds 1000, it cannot be detected, but the length that the variable can receive does not seem to exceed 1000.
Another option:
The code is as follows:
@ echo off
:: Based on willsort's codes code by JM 2006-10-9 CMD@XP
:: source: http://www.cn-dos.net/forum/viewthread.php?tid=19819
Set mystr=
Set / p mystr= enter the string to calculate the length (directly enter exit):
If not defined mystr goto: eof
Set count=0
Setlocal enabledelayedexpansion
: intercept
Set / a count+=1
For / f% I in ("% count%") do if not "! mystr:~%%i,1!" = "" goto intercept
Echo length:% count%
Pause
Goto: eof
@ echo off
::
::
: began
Set / p mystr= enter the string for which you want to calculate the length:
Echo% mystr:~0,1% | findstr / I "Q" 1 > nul 2 > nul & & exit rem enter Q to exit
Call: bflen "% mystr%" rem these two sentences call bflen, returning the length to the variable ret.
Echo string: "% mystr%"
Echo length:% ret%
Goto began
Bflen rem is really troublesome. Initialization should be taken out separately.
Set num=
Set str=
Set ret=
Set str=%1
Len rem calculates string length
Set str=%str:~0,-1%
Set / a num =% num% + 1
If defined str goto len
Set / a ret =% num%-2
Set num=
Goto: eof
The above is all the contents of the article "how to calculate the length of a string in batches". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.