Search code examples
batch-file

Replace character of string in batch script


I need to replace character * from a string which is some what like this:
*10.*31.**2.*65

I want to remove all the * from this string using batch script.


Solution

  • @ECHO OFF
    SETLOCAL
    SET mystring=*10.31.*2.*65
    :deaster
    FOR /f "tokens=1* delims=*" %%i IN ("%mystring%") DO (
       SET mystring=%%j
       IF DEFINED mystring (
          SET mystring=%%i%%j
          GOTO deaster
       ) ELSE (
          SET mystring=%%i
       )
    )
    ECHO result=%mystring%=