0 Pluspunkte 0 Minuspunkte

Angenommen ich habe den String

Hello world, today is not a not good day

und möchte nur das erste Vorkommen von "not" daraus entfernen wie mache ich das?

bezieht sich auf eine Antwort auf: Substring aus einem String entfernen
von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

Mit einer Funktion

@Echo OFF
SETLOCAL Enabledelayedexpansion

set "strpath=Hello this is not a not good day"

call :REPLACE_FIRST "%strpath%" "not" ""

echo !replaced_str!

goto:eof


:REPLACE_FIRST
Set "str=%~1"
Set "word_before=%~2"
Set "word_after=%~3"
Set "splited_str=%str:\=\ %"

FOR %%# in (%splited_str%) do (
    IF "%%#" EQU "!word_before!" (
        Set "replaced_str=!replaced_str!!word_after!"
        Set "word_before="
    ) ELSE (
        Set "replaced_str=!replaced_str!%%# "
    )
)

:eof
von (716 Punkte)