PC Review


Reply
Thread Tools Rate Thread

Character substitution in %variable

 
 
Rich Pasco
Guest
Posts: n/a
 
      8th Nov 2007
Someone must have thought of an easy way to do this:

I would like to replace every underscore with a blank in %variable
in a command-shell script (BAT file).

For example, if %%A is
"The_quick_brown_fox_jumps_over_the_lazy_dog"
then I would like to quickly generate
"The quick brown fox jumps over the lazy dog"

I can think of several ways, but they're all pretty long and kludgy.
Can anybody think of an elegant solution?

- Rich

 
Reply With Quote
 
 
 
 
Rich Pasco
Guest
Posts: n/a
 
      8th Nov 2007
Rich Pasco wrote:

> Someone must have thought of an easy way to do this:
>
> I would like to replace every underscore with a blank in %variable
> in a command-shell script (BAT file).
>
> For example, if %%A is
> "The_quick_brown_fox_jumps_over_the_lazy_dog"
> then I would like to quickly generate
> "The quick brown fox jumps over the lazy dog"
>
> I can think of several ways, but they're all pretty long and kludgy.
> Can anybody think of an elegant solution?
>
> - Rich


Here's one of those long, kudgy ways:

> for /F "tokens=1,2,3,4,5,6,7,8,9 delims=_" %%g in ("%%f") do echo %%g %%h %%i %%j %%k %%l %%m %%n %%o


 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      8th Nov 2007

"Rich Pasco" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rich Pasco wrote:
>
>> Someone must have thought of an easy way to do this:
>>
>> I would like to replace every underscore with a blank in %variable
>> in a command-shell script (BAT file).
>>
>> For example, if %%A is
>> "The_quick_brown_fox_jumps_over_the_lazy_dog"
>> then I would like to quickly generate
>> "The quick brown fox jumps over the lazy dog"
>>
>> I can think of several ways, but they're all pretty long and kludgy.
>> Can anybody think of an elegant solution?
>>
>> - Rich

>
> Here's one of those long, kudgy ways:
>
>> for /F "tokens=1,2,3,4,5,6,7,8,9 delims=_" %%g in ("%%f") do echo %%g %%h
>> %%i %%j %%k %%l %%m %%n %%o

>


set var=The_quick_brown_fox_jumps_over_the_lazy_dog
set var=%var:_= %
echo %var%



 
Reply With Quote
 
Rich Pasco
Guest
Posts: n/a
 
      8th Nov 2007
billious wrote:

>> Rich Pasco wrote:
>>
>>> Someone must have thought of an easy way to do this:
>>>
>>> I would like to replace every underscore with a blank in %variable
>>> in a command-shell script (BAT file).
>>>
>>> For example, if %%A is
>>> "The_quick_brown_fox_jumps_over_the_lazy_dog"
>>> then I would like to quickly generate
>>> "The quick brown fox jumps over the lazy dog"
>>>
>>> I can think of several ways, but they're all pretty long and kludgy.
>>> Can anybody think of an elegant solution?

>
> set var=The_quick_brown_fox_jumps_over_the_lazy_dog
> set var=%var:_= %
> echo %var%


Perfect! Exactly what I wanted! Thank you!

- Rich
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable substitution doobie Microsoft Excel Misc 1 9th Nov 2009 05:36 PM
character substitution =?Utf-8?B?Z29yZCBwaGxhbg==?= Microsoft Word Document Management 7 1st Sep 2007 06:01 PM
URL Character substitution jeronimo13@gmail.com Windows XP Internet Explorer 0 16th Jun 2005 02:23 PM
Email Character substitution =?Utf-8?B?SmltIE1vbHRlcg==?= Microsoft Outlook Discussion 0 3rd May 2005 06:37 PM
VARIABLE SUBSTITUTION Robert Lowe Microsoft Excel Programming 3 23rd Apr 2004 04:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:54 PM.