|
Answer» Is it possible to tokenize a given string, character by character, when no DELIMITERS are present? E.G., if the string contained "abcd" instead of "a,b,c,d".
Or, from the opposite way of thinking, is it possible to automatically insert delimiters into a string once per character?
Perhaps you would have to build the string, character by character using string manipulation on your input....but how could you automate string manipulation commands(:~x,y) to move/progress that way?Hi Greg.
Here's a start for you to improve on. The addition of the # char to the string is just to GIVE something to test for end-of-string and can be any character. The For loop is just to demo output.
Code: [Select]echo off cls
setlocal enabledelayedexpansion
set string=abcdefg# set pos=0
:start CALL set chr=%%string:~%pos%,1%% if !chr!==# goto finis set var1=!var1!!chr!, set /a pos+=1 goto start
:finis set var1=!var1:~0,-1!
for /F "tokens=1-%pos% delims=," %%A in ("%var1%") do ( set var2=%%A%%B set var3=%%B%%F%%G ) echo String Variable =%string:~0,-1% echo CSV string =!var1! echo Tokens=Pos=!pos! echo Var2=%var2% echo Var3=%var3%
|