Page 1 of 1

Process Chars

Posted: 16 Jun 2011 23:14
by Cleptography
Is there a way to process each char in a string and after each one has been compared put it back together and echo it as the original string.
So...

Code: Select all

The quick brown fox jumped over the lazy dog

Now, I want to check each character in the string and echo them one by one but not like
T
h
e
Can this be done?

Re: Process Chars

Posted: 17 Jun 2011 03:12
by jeb
What do you want to try?

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set "text=The quick brown fox jumped over the lazy dog"
set "result="
for /L %%n in (0,1,60) do (
  set "char=!text:~%%n,1!"
  if defined char (
    if !char!==e set "char=*"
    set "result=!result!!char!"   
  )
)
echo !result!


Output wrote:Th* quick brown fox jump*d ov*r th* lazy dog


jeb

Re: Process Chars

Posted: 17 Jun 2011 18:09
by Cleptography
God I love your genius, thank you Jeb.
What needs to happen is for each char to be checked and if $ is found prefixed in the sub string it needs to get everything up to the next space and replace it with another string. The other problem is if the last sub string is prefixed with $ the script hangs and will not exit properly. So if Planet is prefixed with $ error. I will say for argument sake that $World $Hello are variables that exist in an external text file and need to be replaced with the values in the text file that are set.