Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to determine the length of a string in batch processing

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to judge the length of a string in batch processing, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

Exercise 1.1 the string length does not exceed 80. No special characters

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

1.2 the string length is less than 255 and contains special characters. Try to find its length.

For example,% a%% verfdxcweippo opj x ds gw & ^ * ~ are you o k? ":\ / ``verdict!%%

In general, ask the question of 1.1 first. See whose code is flexible, concise and clear. And then do 1.2.

(sweat. There is no need to think about Chinese.)

In fact, I also want to solicit a better way. It is estimated that if there is Chinese. Maybe you can redirect to the text and then judge the bytes. I guess so.

Finally: more than one problem, don't just use the method of redirecting the text.

523066680:

The code is as follows:

@ echo off

Echo,i like the bathome,because here is the batch of the world. > x.x

For / f "tokens=*"% an in ('dir x.x /-c ^ | find "bytes" ^ | 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:

The code is as follows:

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

@ echo off&setlocal enabledelayedexpansion

Set / p str=

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report