Batch File Replacing Text With Numbers

December 23, 2010 at 11:29:40
Specs: Windows 7
http://www.computing.net/answers/pr...

I've been working with the script above (provided in post #9), and I have a couple of questions.

1) "5d123=N" & "5d123=I" are the same, won't that output incorrectly?
2) I have been trying for two long days now to add numbers and make the script work. The closest I've come is:

::The File
@echo off
:encrypt
SetLocal EnableDelayedExpansion
set /p qwer=

for %%a in ("A=1º" "B=2º3" "C=4º51" "D=5º123" "E=1º2345" "F=1¼" "G=2¼4" "H=4¼51" "I=5¼321" "J=1¼5432" "K=1¼" "L=2¼3" "M=4¼15" "N=5¼123" "O=1¼2345" "P=1»" "Q=2»3" "R=4»51" "S=5»123" "T=1»2345" "U=1È" "V=2È3" "W=4È51" "X=5È123" "Y=1È2345" "Z=1É" " =2É3" "1=1Å" "2=2Å3" "3=4Å51" "4=5Å123" "5=1Å12345" "6=1ô" "7=2ô4" "8=4ô51" "9=5ô123" "0=1ô2345") do set qwer=!qwer:%%~a!
for %%a in ("É=a" "È=b" "»=c" "¼=d" "º=e" "Î=f" "Å=g" "ô=h") do set qwer=!qwer:%%~a!
echo %qwer% >"%userprofile%\desktop\text.txt"
pause


:decrypt
set qwert=
for /F "usebackq delims=" %%i in ("%userprofile%\desktop\text.txt") do set qwert=!qwert! %%i
set qwer=%qwert%
for %%a in ("1g12345=5" "5g123=4" "4g51=3" "2g3=2" "1g=1" "5d123=n" "1d2345=o" "1b2345=y" "5d321=i" "1d5432=j" "1e2345=e" "1c2345=t" "5e123=d" "5c123=s" "5b123=x" "4b51=w" "4c51=r" "4d51=h" "4e51=c" "4d15=m" "2e3=b" "2d4=g" "1d=k" "2d3=l" "1c=p" "2c3=q" "1b=u" "2b3=v" "1a=z" "2a3= " "1e=a" "1d=f" "5h123=9" "1h2345=0" "4h51=8" "2h4=7" "1h=6") do call set qwer=%%qwer:%%~a%%
echo %qwer%
pause
::END

It works well, except...

I was playing around with it, typing some random things for fun to test it, when I typed in "911helpme" The output was "916elpme" I discovered it was because of the "1h" in "911helpme". As you can see above, "1h=6". I started trying other ones, typing in "2b3", but the output was not "2b3" it was "v".

I want to pre-thank anyone who can help me with these two questions: Thankyou.


See More: Batch File Replacing Text With Numbers

Report •

#1
December 24, 2010 at 16:19:56
I wrote this to convert text to morse code. You can edit the equivalents which start at line 37. No provision is made for NUMS, only chars and SPACE.

===========================================

@echo off & setLocal EnableDELAYedeXpansion & set B=%0

if not %1'==' (set S=%*) else (set /p S=string ? :)
call :xlat
call :StrLen !S!
for /L %%i in (0 1 !E!) do (
  set C=!S:~%%i^,1!
  if "!C!"==" " (
  set M=!M!!C!
  ) else (call :Vset !C!
  set M=!M!!C!
  )
)
echo.!M!
goto :eof

:xlat
for /f "skip=36 tokens=1-2 delims= " %%a in (!B!.bat) do (
set V%%a=%%b
)
goto :eof

:StrLen %*
set LEN=0
set Data=%*
for /L %%a in (0,1,80) do (
  set Char=!Data:~%%a,1!
  if not "!Char!"=="" set /a LEN+=1
)
set /a E=LEN-1
goto :eof

:Vset
set C=!V%1!
goto :eof
::===========================================
A  .-
B  -...
C  -.-.
D  -..
E  .
F  ..-.
G  --.
H  ....
I  ..
J  .---
K  -.-
L  .-..
M  --
N  -.
O  ---
P  .--.
Q  --.-
R  .-.
S  ...
T  -
U  ..-
V  ...-
W  .--
X  -..-
Y  -.--
Z  --..


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 24, 2010 at 21:25:52
@Smts: dude i'm loving this program it's brilliant :)

Report •

#3
December 25, 2010 at 23:35:28
Batch doesn't recognize unicode characters. You need to stick with ASCII. You will also need to escape special characters. like brackets (parentheses), ampersands, carets, etc.

Ex. ^&, ^(, ^) ...

Can I put a question here?


Report •

Related Solutions

#4
December 30, 2010 at 17:42:10
This isn't working for me. I am getting an error saying that the program can't find the batch file specified, and the window closes quickly. Any Ideas?

Report •

#5
December 30, 2010 at 23:06:00
LOL *WHAT* isn't working?


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
January 5, 2011 at 20:04:40
LOL *I am getting an error saying that the program can't find the batch file specified, and the window closes quickly* isn't working. Any Ideas?

Report •

#7
January 5, 2011 at 20:17:49
Thankyou Nfinch

Report •

#8
January 5, 2011 at 22:39:28
"window closes", my butt.Run it at the prompt.


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question