Split input

S

Sheldon

I have a batch file that takes two email addresses as inputs. How can I
split the email addresses into variables for usernames and variables for the
domain names?
 
A

Al Dunbar [MS-MVP]

Sheldon said:
I have a batch file that takes two email addresses as inputs. How can I
split the email addresses into variables for usernames and variables for the
domain names?

Perhaps this will work (tested only on XP):


@echo off

:next
(set _email=)
(set/p _email=enter an _email address: )
if not defined _email goto:eof
for /f "tokens=1,2 delims=@" %%F in ('echo/%_email%') do (
set _user=%%F
set _domain=%%G
)
set _
echo/
goto:next
 
S

Sheldon

Al Dunbar said:
Perhaps this will work (tested only on XP):


@echo off

:next
(set _email=)
(set/p _email=enter an _email address: )
if not defined _email goto:eof
for /f "tokens=1,2 delims=@" %%F in ('echo/%_email%') do (
set _user=%%F
set _domain=%%G
)
set _
echo/
goto:next

That's excellent. Works fine on Windows 2000 Server and 2003 Server.

Thanks very much for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top