Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Changing guids to uppercase

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-20-2007   #1 (permalink)
p2
Guest


 

Changing guids to uppercase

I have a file (XML file) that has GUIDs sprinkled througout it. I would like
to convert all the GUIDs to upper-case. I would have thought that this would
work but I can't quite figure it out.

(get-content filename) -replace "[0-9a-fA-F-]{36}", ([string]'$0').toupper()

The regex expression is matching correctly but the $0.toupper() simply isn't
working. What am I missing?

Any hints appreciated...

My System SpecsSystem Spec
Old 03-21-2007   #2 (permalink)
Keith Hill
Guest


 

Re: Changing guids to uppercase

"p2" <p2@discussions.microsoft.com> wrote in message
newsF01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...
>I have a file (XML file) that has GUIDs sprinkled througout it. I would
>like
> to convert all the GUIDs to upper-case. I would have thought that this
> would
> work but I can't quite figure it out.
>
> (get-content filename) -replace "[0-9a-fA-F-]{36}",
> ([string]'$0').toupper()
>
> The regex expression is matching correctly but the $0.toupper() simply
> isn't
> working. What am I missing?
>
> Any hints appreciated...


Well I can tell you why it is not working but I haven't come up with an easy
solution to the problem. The reason it doesn't work is that the $1 (should
be 1 instead of 0) is only evaluated by the regex engine. So $1 isn't
meaningful to PowerShell (most like is null) so calling ToUpper only results
in an empty replacement string. Now if -replace supported a scriptblock
that would be called for match evaluation (which is supported by .NET) then
something like this would be easy:

# !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0
$hexCh = "[a-fA-F0-9]"
$guidPattern =
[regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})"
(get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()}

Now that would be wicked cool if this support were added. I think I will
file this as an enhancement request on the connect site alongside my request
for -matchall.

Maybe somebody who is a bit more regex savy can come up with a regex way to
capitalize with the .NET regex engine but since the examples for the
MatchEvaluator delegates were demonstrating capitalization, I kind of doubt
it. If you knew there was ever only one GUID per line then it would
probably be easy to use -match to grab the GUID via the $matches variable
and then capitalize that guid. Then turn around and use replace on the same
line to replace the guid with the capitalized version.

--
Keith

My System SpecsSystem Spec
Old 03-21-2007   #3 (permalink)
Keith Hill
Guest


 

Re: Changing guids to uppercase

"Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> wrote in message
news:O5bG6u3aHHA.348@TK2MSFTNGP02.phx.gbl...
> "p2" <p2@discussions.microsoft.com> wrote in message
> newsF01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...
> in an empty replacement string. Now if -replace supported a scriptblock
> that would be called for match evaluation (which is supported by .NET)
> then something like this would be easy:
>
> # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0
> $hexCh = "[a-fA-F0-9]"
> $guidPattern =
> [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})"
> (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()}
>
> Now that would be wicked cool if this support were added.


If anyone else likes this idea you can vote on it here:

https://connect.microsoft.com/feedba...4447&SiteID=99

--
Keith

My System SpecsSystem Spec
Old 03-21-2007   #4 (permalink)
Andrew Savinykh
Guest


 

Re: Changing guids to uppercase

There is a blog entry from Bruce Payette:
http://blogs.msdn.com/powershell/arc...25/678259.aspx

I think once powershell supports an easier way to work with delegates,
the standard MatchEvaluator solution will do. The advantage is that it
leverages existing .net paradigm so it is well known. Adding an ability
to specify MatchEvaluator in the -replace operator may be nice too.

//Andrew

Keith Hill wrote:
> "p2" <p2@discussions.microsoft.com> wrote in message
> newsF01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...
>> I have a file (XML file) that has GUIDs sprinkled througout it. I
>> would like
>> to convert all the GUIDs to upper-case. I would have thought that this
>> would
>> work but I can't quite figure it out.
>>
>> (get-content filename) -replace "[0-9a-fA-F-]{36}",
>> ([string]'$0').toupper()
>>
>> The regex expression is matching correctly but the $0.toupper() simply
>> isn't
>> working. What am I missing?
>>
>> Any hints appreciated...

>
> Well I can tell you why it is not working but I haven't come up with an
> easy solution to the problem. The reason it doesn't work is that the $1
> (should be 1 instead of 0) is only evaluated by the regex engine. So $1
> isn't meaningful to PowerShell (most like is null) so calling ToUpper
> only results in an empty replacement string. Now if -replace supported
> a scriptblock that would be called for match evaluation (which is
> supported by .NET) then something like this would be easy:
>
> # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0
> $hexCh = "[a-fA-F0-9]"
> $guidPattern =
> [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})"
> (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()}
>
> Now that would be wicked cool if this support were added. I think I
> will file this as an enhancement request on the connect site alongside
> my request for -matchall.
>
> Maybe somebody who is a bit more regex savy can come up with a regex way
> to capitalize with the .NET regex engine but since the examples for the
> MatchEvaluator delegates were demonstrating capitalization, I kind of
> doubt it. If you knew there was ever only one GUID per line then it
> would probably be easy to use -match to grab the GUID via the $matches
> variable and then capitalize that guid. Then turn around and use
> replace on the same line to replace the guid with the capitalized version.
>
> --
> Keith

My System SpecsSystem Spec
Old 03-21-2007   #5 (permalink)
/\/\o\/\/ [MVP]
Guest


 

Re: Changing guids to uppercase

did go the same way (matchevaluator and post by Bruce, as you can use the
delegate directly.

it will work now, as you do not need the match (ok not so usefull but as
example)
but to catch that you need to change the delegate as show in the post by
Bruce.

PoSH> [regex]::Replace("foo",".*",{get-date}.invoke())
03/21/2007 11:29:1703/21/2007 11:29:17

Greetings /\/\o\/\/

"Andrew Savinykh" wrote:

> There is a blog entry from Bruce Payette:
> http://blogs.msdn.com/powershell/arc...25/678259.aspx
>
> I think once powershell supports an easier way to work with delegates,
> the standard MatchEvaluator solution will do. The advantage is that it
> leverages existing .net paradigm so it is well known. Adding an ability
> to specify MatchEvaluator in the -replace operator may be nice too.
>
> //Andrew
>
> Keith Hill wrote:
> > "p2" <p2@discussions.microsoft.com> wrote in message
> > newsF01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...
> >> I have a file (XML file) that has GUIDs sprinkled througout it. I
> >> would like
> >> to convert all the GUIDs to upper-case. I would have thought that this
> >> would
> >> work but I can't quite figure it out.
> >>
> >> (get-content filename) -replace "[0-9a-fA-F-]{36}",
> >> ([string]'$0').toupper()
> >>
> >> The regex expression is matching correctly but the $0.toupper() simply
> >> isn't
> >> working. What am I missing?
> >>
> >> Any hints appreciated...

> >
> > Well I can tell you why it is not working but I haven't come up with an
> > easy solution to the problem. The reason it doesn't work is that the $1
> > (should be 1 instead of 0) is only evaluated by the regex engine. So $1
> > isn't meaningful to PowerShell (most like is null) so calling ToUpper
> > only results in an empty replacement string. Now if -replace supported
> > a scriptblock that would be called for match evaluation (which is
> > supported by .NET) then something like this would be easy:
> >
> > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0
> > $hexCh = "[a-fA-F0-9]"
> > $guidPattern =
> > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})"
> > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()}
> >
> > Now that would be wicked cool if this support were added. I think I
> > will file this as an enhancement request on the connect site alongside
> > my request for -matchall.
> >
> > Maybe somebody who is a bit more regex savy can come up with a regex way
> > to capitalize with the .NET regex engine but since the examples for the
> > MatchEvaluator delegates were demonstrating capitalization, I kind of
> > doubt it. If you knew there was ever only one GUID per line then it
> > would probably be easy to use -match to grab the GUID via the $matches
> > variable and then capitalize that guid. Then turn around and use
> > replace on the same line to replace the guid with the capitalized version.
> >
> > --
> > Keith

>

My System SpecsSystem Spec
Old 03-21-2007   #6 (permalink)
/\/\o\/\/ [MVP]
Guest


 

Re: Changing guids to uppercase

forget example plz ;-) as trhis is same as (get-date)

"/\/\o\/\/ [MVP]" wrote:

> did go the same way (matchevaluator and post by Bruce, as you can use the
> delegate directly.
>
> it will work now, as you do not need the match (ok not so usefull but as
> example)
> but to catch that you need to change the delegate as show in the post by
> Bruce.
>
> PoSH> [regex]::Replace("foo",".*",{get-date}.invoke())
> 03/21/2007 11:29:1703/21/2007 11:29:17
>
> Greetings /\/\o\/\/
>
> "Andrew Savinykh" wrote:
>
> > There is a blog entry from Bruce Payette:
> > http://blogs.msdn.com/powershell/arc...25/678259.aspx
> >
> > I think once powershell supports an easier way to work with delegates,
> > the standard MatchEvaluator solution will do. The advantage is that it
> > leverages existing .net paradigm so it is well known. Adding an ability
> > to specify MatchEvaluator in the -replace operator may be nice too.
> >
> > //Andrew
> >
> > Keith Hill wrote:
> > > "p2" <p2@discussions.microsoft.com> wrote in message
> > > newsF01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...
> > >> I have a file (XML file) that has GUIDs sprinkled througout it. I
> > >> would like
> > >> to convert all the GUIDs to upper-case. I would have thought that this
> > >> would
> > >> work but I can't quite figure it out.
> > >>
> > >> (get-content filename) -replace "[0-9a-fA-F-]{36}",
> > >> ([string]'$0').toupper()
> > >>
> > >> The regex expression is matching correctly but the $0.toupper() simply
> > >> isn't
> > >> working. What am I missing?
> > >>
> > >> Any hints appreciated...
> > >
> > > Well I can tell you why it is not working but I haven't come up with an
> > > easy solution to the problem. The reason it doesn't work is that the $1
> > > (should be 1 instead of 0) is only evaluated by the regex engine. So $1
> > > isn't meaningful to PowerShell (most like is null) so calling ToUpper
> > > only results in an empty replacement string. Now if -replace supported
> > > a scriptblock that would be called for match evaluation (which is
> > > supported by .NET) then something like this would be easy:
> > >
> > > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0
> > > $hexCh = "[a-fA-F0-9]"
> > > $guidPattern =
> > > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})"
> > > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()}
> > >
> > > Now that would be wicked cool if this support were added. I think I
> > > will file this as an enhancement request on the connect site alongside
> > > my request for -matchall.
> > >
> > > Maybe somebody who is a bit more regex savy can come up with a regex way
> > > to capitalize with the .NET regex engine but since the examples for the
> > > MatchEvaluator delegates were demonstrating capitalization, I kind of
> > > doubt it. If you knew there was ever only one GUID per line then it
> > > would probably be easy to use -match to grab the GUID via the $matches
> > > variable and then capitalize that guid. Then turn around and use
> > > replace on the same line to replace the guid with the capitalized version.
> > >
> > > --
> > > Keith

> >

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Typewriting lowercase after uppercase letters quickly Erhard Glueck Vista performance & maintenance 7 01-10-2008 01:50 AM
media changing delays when changing tracks cozzie2 Vista music pictures video 21 05-16-2007 09:34 PM
Changing the way of changing the colorscheme Tipsko Vista General 1 02-27-2007 05:35 AM
Duplicate GUIDS... Ross Vista installation & setup 0 01-22-2007 04:04 PM
Duplicate GUIDs... Ross Vista installation & setup 0 01-22-2007 04:03 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008