To remove everything after the first comma you can use
@echo off
setlocal enabledelayedexpansion
set str=aaaaa,bbbbb,ccccc,dddd
for /f "delims=," %%a in ("%str%") do (
set str=%%a
echo !str!
)
pause >nul
To replace, simply strip it and append the new string on the end
set str=%%a,new,string
Update
This will do the same, but without a for loop
@echo off
setlocal enabledelayedexpansion
set str=aaaaa,bbbbb,ccccc,dddd
set strip=%str%
set length=0
set start=0
set new=
:loop
if defined strip (
set strip=!strip:~1!
set /a length+=1
goto :loop
)
:comma
if %length% gtr 0 (
call :add !start!
if "!char!"=="," (
goto :break
) else (
set new=!new!!char!
set /a length-=1
set /a start+=1
goto comma
)
)
:break
echo %new%
pause >nul
:add
set char=!str:~%1,1!
,(comma) and I cant do it in a FOR loop