Get the App
SLTechnology News&Howtos  ›  Development  › 

How to determine the length of a string in batch processing

Shulou Source: shulou.com Published: 2022-06-03 07:53:25 10月04日 Update

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=

Tags: Characters length strings code articles special bytes text x.x simplicity no exercises values interests methods and at the same time ideas I guess methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Shulou Information MariaDB MySQL