windows - "delims=#+#" - more then 1 character as delimiter -


is possible define delimiter not limited 1 character? based on title's example, define separator e.g. '#+#'. textfiles/lines can contain both characters, there little chance you'll come across particular substring/text combo.

no, can not use string delimiter in delims= clause. of course can include string, handled set of separate characters used delimiters, not delimiter string.

if need split on string, fastest approach replace delimiter string character not included in data , use character delimiter

@echo off     setlocal enableextensions disabledelayedexpansion      /f "delims=" %%a in ("this +test!! #+# of string #splitting#") (         set "buffer=%%a"         setlocal enabledelayedexpansion         (for /f "tokens=1,2 delims=¬" %%b in ("!buffer:#+#=¬!") (             endlocal             echo full line    : [%%a]             echo first token  : [%%b]             echo second token : [%%c]         )) || if "!!"=="" endlocal      ) 

note: setlocal enabledelayedexpansion needed able read variable changed inside for loop retrieving data (here simulated directly including string). then, inside for loop tokenizes readed line, delayed expansion disabled avoid problems ! characters (if delayed expansion active, consumed parser). reason endlocal inside loop.

as doing string replacement , possible end string composed of delimiters, possible do clause of inner for not executed, final if included ensure enabledelayedexpansion cancelled.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -