1.

Solve : Documentation for String Length?

Answer»

I was on SO and came across this post that asked how to break a string by delimiter and then count how many strings exist. The given answer(at the time) was this:

Code: [Select]echo off
SET "string=17.09.01.04.03"
set count=0
for %%a in (%string:.= %) do set /a count+=1
echo %count%
Is it DOCUMENTED anywhere that %string:.= % will break the string on the period?It won't break the string into sub strings but will only determine the count of the sub strings.Thanks the for quick reply 

Is there documentation somewhere that SAYS the code %string:.= % will provide the count? I'm just wondering how the PERSON who posted the answer was able to figure it out.See this:
http://www.dostips.com/DtTipsStringOperations.php#Snippets.Replace Quote from: QueenSvetlana on June 12, 2017, 11:10:44 AM

I'm just wondering how the person who posted the answer was able to figure it out.
It's just putting basic batch stuff together. They knew these things:

1. This is an example of batch string replacement: %string:.= % It means "the variable %string%, with each period (dot) changed to a space"

2. The replacement makes 17.09.01.04.03 become 17 09 01 04 03

3. A simple FOR command repeats once for each space-separated token

4. The variable %count% is set to 0 (zero) at the beginning.

5. Each time FOR repeats, the set /a count+=1 adds 1 (one) to the value of %count%

6. At the end, %count% is equal to the number of tokens.




Discussion

No Comment Found