Page 1 of 1

Characters of a string

Posted: 07 Oct 2013 22:17
by pumi
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

Re: Characters of a string

Posted: 07 Oct 2013 23:58
by foxidrive
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?

Re: Characters of a string

Posted: 08 Oct 2013 00:37
by pumi
The characters are only alpha-numeric.
Simple solution is ok.
thanks

Re: Characters of a string

Posted: 08 Oct 2013 00:53
by foxidrive
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

Re: Characters of a string

Posted: 08 Oct 2013 05:15
by pumi
thanks, this works!