ho la seguente stringa all'interno del mio file batch di Windows:Rimuovere primo e l'ultimo carattere di una stringa in un file batch di Windows
"-String"
La stringa contiene anche i marchi twoe virgolette all'inizio e alla fine del la stringa, così come è scritta sopra.
Voglio mettere a nudo il primo e l'ultimo carattere in modo che ricevo la seguente stringa:
-String
ho provato questo:
set currentParameter="-String"
echo %currentParameter:~1,-1%
Questo stampa la stringa come dovrebbe essere:
-String
Ma quando provo a memorizzare la stringa modificata in questo modo, non riesce:
set currentParameter="-String"
set currentParameter=%currentParameter:~1,-1%
echo %currentParameter%
Non viene stampato nulla. Cosa faccio di sbagliato?
Questo è davvero strano. Quando ho rimuovere i caratteri come questo funziona:
set currentParameter="-String"
set currentParameter=%currentParameter:~1,-1%
echo %currentParameter%
esso stampa:
-String
Ma in realtà il mio gruppo è un po 'più complicato e là non funziona. Vi mostrerò che cosa ho programmato:
@echo off
set string="-String","-String2"
Set count=0
For %%j in (%string%) Do Set /A count+=1
FOR /L %%H IN (1,1,%COUNT%) DO (
echo .
call :myFunc %%H
)
exit /b
:myFunc
FOR /F "tokens=%1 delims=," %%I IN ("%string%") Do (
echo String WITHOUT stripping characters: %%I
set currentParameter=%%I
set currentParameter=%currentParameter:~1,-1%
echo String WITH stripping characters: %currentParameter%
echo .
)
exit /b
:end
e l'uscita è:
.
String WITHOUT stripping characters: "-String"
String WITH stripping characters:
.
.
String WITHOUT stripping characters: "-String2"
String WITH stripping characters: ~1,-1
.
Ma quello che voglio è:
.
String WITHOUT stripping characters: "-String"
String WITH stripping characters: -String
.
.
String WITHOUT stripping characters: "-String2"
String WITH stripping characters: -String2
.
tue opere campione (come previsto), ci deve essere un altro bug . Forse l'hai provato all'interno di un blocco? – jeb
Viene visualizzato il seguente messaggio: 'ECHO ist ausgeschaltet (OFF). ~ 1, -1' – Metalhead89
Forse è perché è in una funzione? ': myFunc FOR/F "tokens =% 1 delims =" %% I IN ("% processChain1%") Do ( \t set currentParameter = %% I \t set currentParameter =% currentParameter: ~ 1 , -1% \t echo% currentParameter% \t rem java -jar app.jar %% I ) uscita/b' – Metalhead89