Author Topic: [BAT] Divide per character a text string  (Read 681 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9956
  • Karma: +2285/-111
[BAT] Divide per character a text string
« on: January 20, 2016, 03:05:16 PM »
Hello TechKnow members and visitors!

I needed a simple functions to cut / divide a text string using batch for work.

So I've come up with this little simple script:

Code: (CHARDIVIDER.BAT) [Select]
@echo off

if "%1"=="" echo NO INPUT FOUND! && goto :EOF

SET strterm=_

REM get first character from tmpX
SET char=%tmpX:~0,1%

REM remove first character from tmpX
SET tmpX=%tmpX:~1%

REM actions for character
echo chardivider output: %char%

REM Loop until the string terminator is reached in tmpX
IF NOT "%tmpX%" == "%strterm%" GOTO :STRINGCUTTER


A little note, it uses a "_" character to terminate the command, if your data contains this character, be sure to use another terminator.