I need to automate a boring action that I already implemented for OSX. However, I am stuck in my "language" translation because I can't find the way, based on the example below, that I have 3 \
in the next string:
..\..\..\..
PS: I couldn't find to make work "cd -" in CMD.
I have the following function I created:
:: Count the occurrences of a certain char in the given string
:: $~1 (input) String
:: $~2 (char) Char to be found & counted
:count_occurrences
set input=%1
set char=%2
set count=0
for %%a in ("%input:\= " "%") do set /A count+=1
echo. %count%
SET %~3=count
EXIT /B 0
However, this returns all the time 1
.. However, to me, based on this example (https://stackoverflow.com/a/41961590/6093604), it should return 3
.
Thanks for any help !
Edit 1 (mostly working)
My code is now the following:
:: Count the occurrences of a certain char in the given string
:: $~1 (input) String
:: $~2 (char) Char to be found & counted
:: $~3 (count) The returned value
:count_occurrences
set "input=%~1"
set "char=%~2"
echo. %input%
for %%a in ("%input:\= " "%") do set /A %~3+=1
EXIT /B 0
How can I use the param 2 $~2
as char to be counted? Because, as I said in my comment, here we only search for \
Thanks again !