Searching for white space in environment variable

  • Thread starter Thread starter awrightus@gmail.com
  • Start date Start date
A

awrightus@gmail.com

Trying to find a way to search for white space in an environment
variable. Batch file running on XP. Let's say I have a variable
test1 that equals "word", but then another that equals "word
another". Trying to to figure out when an environment variable has a
space in it. findstr.exe seems to support regular expressions, so I
thought I could do "findstr /R \s %test1%", but findstr.exe only seems
to want to search files and not variables. Any ideas how to approach
this? Thanks.

Steve
 
<awrightus@gmail.com> wrote in message
news:12f1b3b7-8b17-47bb-a9e3-ede49b17daef@i72g2000hsd.googlegroups.com...
> Trying to find a way to search for white space in an environment
> variable. Batch file running on XP. Let's say I have a variable
> test1 that equals "word", but then another that equals "word
> another". Trying to to figure out when an environment variable has a
> space in it. findstr.exe seems to support regular expressions, so I
> thought I could do "findstr /R \s %test1%", but findstr.exe only seems
> to want to search files and not variables. Any ideas how to approach
> this? Thanks.
>
> Steve


Try this:

echo %test1%|find " ">nul&&echo Space found
 
<awrightus@gmail.com> wrote in message
news:12f1b3b7-8b17-47bb-a9e3-ede49b17daef@i72g2000hsd.googlegroups.com...
> Trying to find a way to search for white space in an environment
> variable. Batch file running on XP. Let's say I have a variable
> test1 that equals "word", but then another that equals "word
> another". Trying to to figure out when an environment variable has a
> space in it. findstr.exe seems to support regular expressions, so I
> thought I could do "findstr /R \s %test1%", but findstr.exe only seems
> to want to search files and not variables. Any ideas how to approach
> this? Thanks.
>
> Steve


Here is a more elegant method.

if not "%test1%"=="%test1: =%" echo Space found
 
Back
Top