Searching for white space in environment variable

A

awrightus

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
 
P

Pegasus \(MVP\)

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
 
P

Pegasus \(MVP\)

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
 

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