Results 1 to 8 of 8

Thread: ~~

  1. #1
    Your very own Pikachu! Banned Peegee's Avatar
    Join Date
    Mar 2001
    Posts
    19,488
    Blog Entries
    81

    Grin Input string with space in dos batch

    I've narrowed it down to this question:

    "In a dos prompt batch input file, how do you input a string that has a space?"

    Eg (simplied to illustrate the point):

    Say you have a file input.txt

    input.txt has the following lines

    "telephone"
    "caterpillar"
    "boeing airplane"

    If you were to run the following batch:

    for /f %%i in (input.txt) do (
    @echo %%i
    )

    You will get the following :

    "telephone"
    "caterpillar"
    "boeing

    Where's the " airplane"?? It doesn't get picked up by echo!

    However if you typed in dos prompt echo "boeing airplane" it would output:

    boeing airplane

    aieee~
    Last edited by Peegee; 06-08-2009 at 06:31 PM. Reason: wtf I thought I wrote the title properly

  2. #2

    Default

    maybe underscore? its been about 4 years since i dealt with dos
    I like chocolate!! No matter what flavor you get, you can always taste the broken dreams!

    ~Dead people should stay dead, otherwise whats the point of killing them???

  3. #3

  4. #4
    diafnaoplzkthnxbai NeoTifa's Avatar
    Join Date
    Jun 2005
    Location
    in psy's panties <3
    Posts
    3,411

    Default

    Could you print the two tokens on the same line? And wtf are you doing with dos anyway?
    Oh gods, why? ಥ_ಥ


  5. #5
    Your very own Pikachu! Banned Peegee's Avatar
    Join Date
    Mar 2001
    Posts
    19,488
    Blog Entries
    81

    Grin

    Quote Originally Posted by NeoTifa View Post
    Could you print the two tokens on the same line? And wtf are you doing with dos anyway?
    It's for work. I'm not sure what you mean by the first sentence ;o

  6. #6
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    Try this code, I'm not that flash with batch scripting in Windows but it worked for me.
    Code:
    for /f "delims=[]" %%i in (input.txt) do (
    @echo %%i
    )

  7. #7
    Your very own Pikachu! Banned Peegee's Avatar
    Join Date
    Mar 2001
    Posts
    19,488
    Blog Entries
    81

    Grin

    That did it, but I'm not sure what that means though. Did you specify something or nothing in the delimiter?

  8. #8
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    The default delimiter value for the windows shell is "&lt;tab&gt;&lt;space&gt;", so the for loop iterates over every value that it can find which is delimited by one of these two characters. By changing the delimiter either to a character you know will never be used or to nothing at all (this is what I did; [] represents a set of no characters) you can force the script to ignore spaces.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •