Special char in string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
pe.ft
Posts: 8
Joined: 21 Sep 2010 13:53

Re: Special char in string

#16 Post by pe.ft » 25 Sep 2010 12:25

orange_batch wrote:No need to get nasty. 8) It depends on what you're doing, but such things may make a difference when processing large amounts of data. For example, using find/findstr to find a substring in a single line must be around a hundred times slower than doing a native substring replace and comparison.


you are right. The code posted by amel27 need high performances, a simple CD need human-time performance, it could be relatively slow. You can see a 'time cost' if in a batch use CDD many times, I never run in trouble.

My approach to the problem was wrong, I try to do something with wrong method. Now I found a way to aliasing commands so no need to wrap the command line in a batch and parse commands (or in the worst case to rewrite a shell).

I have a command line initialization batch file (see as an autoexec.bat) when opening a cmd.exe section, the aliases go there. I also added

Code: Select all

DosKey ..=cd ..

it works with my surprise.

This site has lots of useful dos tips (as the domain suggests), you and many others on this forums are advanced batch programmers, for that reason I asked for a solution but, as I sayd, my approach to the problem was wrong.

Have fun.

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Special char in string

#17 Post by amel27 » 27 Sep 2010 20:26

pe.ft wrote:The code posted by amel27 need high performances
above code slightly optimized by speed:

Code: Select all

@echo off
set "$x=(^1="%%!"!2!"!%%")"
set $y=!=^^%%"

<nul set /p $z="Shaded chars: "& set $y
<nul set /p $z="Text before.: "& set $x
call :shade $x $y
<nul set /p $z="Text after..: "& set $x

EXIT

:shade
  setlocal EnableDelayedExpansion
  set $i=0& set q1="
:shade_loop1
  set $j=0& set "$a=!%~1:~%$i%,1!"
  if not defined $a goto shade_end
:shade_loop2
  set "$b=!%~2:~%$j%,1!"
  if not defined $b set /a $i+=1& set "$s=!$s!!$a!"& goto shade_loop1
  if "!$a!"=="!$b!" if "!$b!"=="%%" (set "$a=%%%%") else set "$a=^^!$a!"
  set /a $j+=1& goto shade_loop2
:shade_end
  for /f %%i in ("!$s!") do endlocal& set "%~1=%%i"
exit /b

Post Reply