how can i get position of a character(s) in a string?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: how can i get position of a character(s) in a string?

#16 Post by dbenham » 03 Jun 2011 15:52

dbenham wrote:
orange_batch wrote:Yeah, I honestly wonder about voodoo syntax like that myself. How the heck does it make any sense? lol

DosItHelp is injecting a command into the string replacement processing.

For a fascinating example of injecting a command into the string replacement process - see the :format function. That function blew me away when I saw it in action. :shock: 8) It helps to run with ECHO ON if you want to understand how it works.

The mechanism of inserting content with ECHO in the :format command is basically the same as truncating the content with REM in DosItHelp's :findstr function.

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

@jeb
Thanks for killing my code! :( You do it so well :)

Your idea looks promising though.

I'm intrigued by the clever trick amel27 used in How to replace "=","*", ":" in a variable. It seems like it could be useful here. If we replaced occurences of search string within target with =, we would only need to apply his trick once to split the string. But three things have held me back from trying this:
  • It is difficult to execute the replace if the search string contains =
  • There might already be an = in the target string - it would have to be replaced before split (again difficult) and restored after (simple)
  • The amount of code it would require. I haven't yet traced through each step of amel27's code to see why it was necessary. It's more complicated than I would have thought.

But if there were ever a situation where we could know that = was not aready present, it seems like it could be useful.

Dave Benham

Post Reply