0

For example, I have this string in another variable:

444455556666&X=697&Y=250

I want to get the number after "&X=" in a variable and the number after "&Y=" in another variable. Is it possible in batch file? Notice: the number 444455556666 is VARIABLE (it can be it can be shorter or longer, so i can't split with the position)

1 Answer 1

3

You have a fine format there: If you split it by &, you get a number, X=nnn, and Y=nnn. Skip the first and use the second and third:

set "var=444455556666&X=697&Y=250"
for /f "tokens=2,3 delims=&" %%x in ("%var%") do set "%%x"&set "%%y"
echo %x%,%y%
Sign up to request clarification or add additional context in comments.

2 Comments

and... what if i had this: "444455556666, 777788889" (any two changing number, divided only by a comma and a space) and i want to get the first number in a variable and the second number in another variable?
for /f "tokens=1,2 delims=, " %%a in ("444455556666, 777788889") do set "first=%%a"&set "second=%%b" Note: if you use a space as delimiter, it has to be the last delim-char.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.