Process Chars

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Process Chars

#1 Post by Cleptography » 16 Jun 2011 23:14

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?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Process Chars

#2 Post by jeb » 17 Jun 2011 03:12

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

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Process Chars

#3 Post by Cleptography » 17 Jun 2011 18:09

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.

Post Reply