Computing.Net > Forums > Programming > Batch parse user input

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch parse user input

Reply to Message Icon

Name: aegis
Date: August 7, 2008 at 14:44:41 Pacific
OS: XP Home SP2
CPU/Ram: AMD 3.8/2gb
Product: Generic
Comment:

i've searched but I can't find out how to parse/extract a couple of characters from a users input. I need the first two right now, but it would be handy to learn how to get any section. I'd really appreciate any help/suggestions.
Is there a 'good' XP Batch tutor somewhere? The ones I've found don't give enough examples.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: August 7, 2008 at 18:18:44 Pacific
Reply:

if you check and READ set /?, you can find the answer to extract substring in cmd. If not, you can use this vbscript


Set objArgs = WScript.Arguments
strUserInput = objArgs(0)
strStart = objArgs(1)
strEnd = objArgs(2)
WScript.Echo Mid(strUserInput,strStart,strEnd)

save the above as test.vbs and on command line(batch),
usage:

C:\test>cscript /nologo test.vbs "userinput" 2 4
seri


0

Response Number 2
Name: aegis
Date: August 7, 2008 at 19:21:34 Pacific
Reply:

Thanks for responding Ghostdog, but I'm afraid I don't understand. I can't use a script, I have to do this with a batch file.

I'm using the following:

set /p q=Enter the name:

and I get q equal to the name that is typed in, but I need to extract the first two characters in q and set another variable to those two characters. I'm sorry if I'm not making things clear.


0

Response Number 3
Name: ghostdog
Date: August 8, 2008 at 00:27:09 Pacific
Reply:

like i said, check out the set /? help. There's a portion that shows you how to do substring.


0

Response Number 4
Name: aegis
Date: August 8, 2008 at 08:47:19 Pacific
Reply:

Sorry about that Ghostdog! I messed up when I did the set /?. I didn't hit a key and only saw the first few lines. I found the 'subset' instructions and will see if my feeble old brain can figure it out and get it to work.
Thanks very much!


0

Response Number 5
Name: aegis
Date: August 8, 2008 at 13:03:07 Pacific
Reply:

OK, I'm pretty slow and it took me quite a while, but after much trial and error I finally got it right. I did it with:
set q=%r:0,2%

Thanks a lot Ghostdog!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch parse user input

Remove quotes from user input string www.computing.net/answers/programming/remove-quotes-from-user-input-string/19410.html

Hiding user input in a Batch File www.computing.net/answers/programming/hiding-user-input-in-a-batch-file/15928.html

Batch file-allowing user input path www.computing.net/answers/programming/batch-fileallowing-user-input-path/16143.html