For Command not Reading Spaces in Words

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

For Command not Reading Spaces in Words

#1 Post by Ranguna173 » 12 May 2013 04:23

Hello people.

I've been using this code to capture chars form phrases (!k wrote it here)

Code: Select all

@echo off &setlocal enableextensions

set "word=everyone!"

call :ch "%word%"
set char
goto :eof

:ch
for /l %%c in (0,1,127) do (
  set "w=%~1"
  call set "char#%%c=%%w:~%%c,1%%"
)
goto :eof


But whenever I change %word% to a word with spaces it won't capture anything that is in front of the space and the space.


Here's an exemple code of !k's code in action with spaces:

Code: Select all

@echo on &setlocal enableDelayedExpansion
@echo on &setlocal enableextensions

:ft2deccharsetter
set "caller=hello hello"
call :ch %caller%
set dis=1
:dis
echo !char#%dis%!
set /a dis+=1
if %dis%==12 set char &echo Supposadly there should be 11 chars to echo but instead it only echos until it reaches the sapce (char 5) &pause
goto dis

:ch
@echo off
for /l %%c in (0,1,127) do (
  set "w=%~1"
  call set "char#%%c=%%w:~%%c,1%%"
)
@echo on
goto :eof


Can somebody help me fix it to work with spaces ?

If you knows how please help me.
And Thanks for reading :D

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: For Command not Reading Spaces in Words

#2 Post by abc0502 » 12 May 2013 05:32

Note the double quotes
call :ch "%caller%"


Always put your variables between double quotes, whether it has spaces or not, that will save you some troubles.

BTW, !k has it between double quotes in his original code

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: For Command not Reading Spaces in Words

#3 Post by Ranguna173 » 12 May 2013 07:17

Augh, how could've I missed that.

Thanks for pointing me that, totally forgot that detail.
Everything works fine now.

Thanks abc0502 for you help :D

Post Reply