Copying first character from a var with space

November 29, 2011 at 11:45:09
Specs: Win7, Intel Core 2 Quad 2.5Ghz / 4GB
So far I have created a batch file that breaks up an entered word and changes each letter to something else and rebuilds it afterwards. So just for now it encrypts a word.

I'm trying to get it to encrypt a sentence including spaces.
The way it works is it grabs the first letter, sets it as variable i, then removes the first letter. This loops till all the input is gone and all the characters have been broken down into pieces.

Here's the code for copying first letter then deleting it. (input = sentence to be broken down)

SET i=%input:~0,1% //copies first letter and saves it into i
SET input=%input:~1% // deletes the first letter

It works perfectly until it reaches a space.
If I enter "Hello World" The window closes as it gets to the space.

How can I get this to copy the space like the rest of the characters?

See More: Copying first character from a var with space

Report •

November 29, 2011 at 12:41:28
This probably isn't what you're looking for but it may get you closer.
this is for a windows 7 .bat

@echo off
echo EXAMPLE 1: ----
echo after typing a single line hit Enter
echo THEN
echo hit Contrl + Z then press enter.
Rem Only one single command line is needed to receive user input
FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET INPUT=%%A
Rem Use quotes if you want to display redirection characters as well
ECHO You typed: "%INPUT%"
echo .
echo .
echo EXAMPLE 2: ----
SET /P INPUT=%1 %2 %3
echo %INPUT%

Report •

November 29, 2011 at 12:52:17
That doesn't help me, sorry.

Report •

December 1, 2011 at 06:29:01
Problem not clear; code works as posted.
Thu 2011.12.01  9.27.22
C:\>set input= abc

Thu 2011.12.01  9.27.30
C:\>set i=%input:~0,1%

Thu 2011.12.01  9.27.45
C:\>set input=%input:~1%

Thu 2011.12.01  9.28.02
C:\>set i

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question