Welcome, guest | Sign In | My Account | Store | Cart

Target: we have a task to split the string ("this is a string") on the characters. Possible solution:

Batch, 16 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
@echo off
  setlocal enabledelayedexpansion
    set "str=this is a string"
    ::at firstly we need to know a length of string
    set "len=0"
    for /l %%i in (0, 1, 255) do (
      set "c=!str:~%%i!"
      if defined c set /a "len+=1"
    )
    ::now we are ready to split string on characters
    set /a "len-=1"
    for /l %%i in (0, 1, !len!) do (
      for /l %%j in (1, 1, 1) do echo."!str:~%%i,%%j!"
    )
  endlocal
exit /b
Created by greg zakharov on Tue, 13 Aug 2013 (MIT)
Batch recipes (42)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks