for /F
combines adjacent delimiters into one for parsing text. You could however read the whole lines, temporarily insert a non-delimiter character for splitting into tokens and remove it later on, like this:
rem // Read whole lines:
for /F "usebackq delims=" %%A in ("MyCSV.txt") do (
rem // Store current line:
set "LINE=%%A"
rem // Toggle delayed expansion to avoid trouble with `!`:
setlocal EnableDelayedExpansion
rem /* Prepend `_` to line string and replace every `/` by `/_`, hence every `/`-delimited
rem item becomes preceded by `_`, hence no more adjacent delimiters `/` can occur: */
for /F "tokens=1-4 delims=/" %%a in ("_!LINE:/=/_!") do (
endlocal
rem // Get items preceded with `_`:
set "ITEM1=%%a"
set "ITEM2=%%b"
set "ITEM3=%%c"
set "ITEM4=%%d"
setlocal EnableDelayedExpansion
rem // Return rebuild line string with delimiters `,` and preceding `_` removed:
echo(!ITEM1:~1!,!ITEM2:~1!,!ITEM3:~1!,!ITEM4:~1!
)
endlocal
)
Of course for just replacing the delimiter character, you could simply do this:
rem // Read whole lines:
for /F "usebackq delims=" %%A in ("MyCSV.txt") do (
rem // Store current line:
set "LINE=%%A"
rem // Toggle delayed expansion to avoid trouble with `!`:
setlocal EnableDelayedExpansion
rem // Return new line string with delimiters replaced:
echo(!ITEM:/=,!
endlocal
)