|
Answer» How Can I parse a STRING in dos
example If I have a string "ServerName/InstanceName" I need ServerName and InstanceName in 2 variables You can do this easily with for. Where is the string coming from? A textfile with a LIST, you read out, or a command output? That makes a difference.
ulistring will be a parameter to the batch file.
Example A.bat AMIT/LOHIA
AMIT/LOHIA will be the string (variable) I need to parse this in 2 variables AMIT - Variable1 LOHIA - Variable2ANY HELP PLEAE!!!!!!!!!!!!!!!!!!!!!!!!!!!Relax Amit. Life in the fast lane can be deadly.
Sometimes it easier to combine two strings into one than split one string into two.
A.bat AMIT LOHIA
This way each part of the string has a reference, %1 and %2. %1=AMIT %2=LOHIA. If you need to combine them use: %1/%2
The other way WOULD be to split the one string
A.bat AMIT/LOHIA
for /f "tokens=1-2 delims=^/" %%a in ("%1") do ( set var1=%%a set var2=%%b )
Var1=AMIT Var2=LOHIA
Simple usually wins out.
|