Characters of a string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pumi
Posts: 15
Joined: 05 Oct 2013 06:48
Location: Germany, BW

Characters of a string

#1 Post by pumi » 07 Oct 2013 22:17

Hello,

is it possible to get every character of a string?
A string like "asdfghjkl".
I want get "a", "s", "d" and so on...
I tried many variants of a foor loop, but nothing works...
Can you give me a hint about that?

thanks in advance and greetings, pumi

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Characters of a string

#2 Post by foxidrive » 07 Oct 2013 23:58

Will the string be alpha-numeric or can there be special characters?
The approach you take will depend on that.

The second question is: do you want a plain batch solution or do you want the simplest solution?

pumi
Posts: 15
Joined: 05 Oct 2013 06:48
Location: Germany, BW

Re: Characters of a string

#3 Post by pumi » 08 Oct 2013 00:37

The characters are only alpha-numeric.
Simple solution is ok.
thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Characters of a string

#4 Post by foxidrive » 08 Oct 2013 00:53

Here's a plain batch solution to parse out each character.

Code: Select all

@echo off
set "string=asdfghjkl"

set "var=%string%"

:loop
set "char=%var:~0,1%"
echo %char%
set "var=%var:~1%"
if defined var goto loop
echo "%string%"

pause

pumi
Posts: 15
Joined: 05 Oct 2013 06:48
Location: Germany, BW

Re: Characters of a string

#5 Post by pumi » 08 Oct 2013 05:15

thanks, this works!

Post Reply