Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

Scripting Games 2007 Beginner PowerShell Event 5

 

I did not enter the beginners PowerShell Division, but did this 2 oneliners for Event 5: ABCs and 123sPS Answer: ABCs and 123s )

in the Beginner division:

$r = $str.tochararray() | % {([int]$_).toString('x')}

[String]::join('',[Char[]]($r |% {[int]"0x$_"}))

So you get the Following output :

 

PoSH> $str = "It was the best of times...you know the rest"                                                             
PoSH> $r = $str.tochararray() | % {([int]$_).toString('x')}                                                             
PoSH> $r                                                                                                                
49                                                                                                                      
74                                                                                                                      
20                                                                                                                      
77                                                                                                                      
61                                                                                                                      
73                                                                                                                      
20                                                                                                                      
74                                                                                                                      
68                                                                                                                      
65                                                                                                                      
20                                                                                                                      
62                                                                                                                      
65                                                                                                                      
73                                                                                                                      
74                                                                                                                      
20                                                                                                                      
6f                                                                                                                      
66                                                                                                                      
20                                                                                                                      
74                                                                                                                      
69                                                                                                                      
6d                                                                                                                      
65                                                                                                                      
73                                                                                                                      
2e                                                                                                                      
2e                                                                                                                      
2e                                                                                                                      
79                                                                                                                      
6f                                                                                                                      
75                                                                                                                      
20                                                                                                                      
6b                                                                                                                      
6e                                                                                                                      
6f                                                                                                                      
77                                                                                                                      
20                                                                                                                      
74                                                                                                                      
68                                                                                                                      
65                                                                                                                      
20                                                                                                                      
72                                                                                                                      
65                                                                                                                      
73                                                                                                                      
74                                                                                                                      
PoSH> [String]::join('',[Char[]]($r |% {[int]"0x$_"}))                                                                  
It was the best of times...you know the rest                                                                            
PoSH> 

 

 For more oneliner fun see : Winter Scripting games Part 2 on my old blog or see the list here for other oneliner solutions the last years events : Scripting Games MMVII PowerShell Competition  

Enjoy,

Greetings /\/\o\/\/

Published Monday, February 19, 2007 5:12 PM by admin

Comments

# re: Scripting Games 2007 Beginner PowerShell Event 5

I see a lot of |% in your blogs, could you tell me what the difference is between |% and | (or just what it's called, so I can google it ;))

Tuesday, February 20, 2007 2:59 AM by Erik Renes

# re: Scripting Games 2007 Beginner PowerShell Event 5

Erik,

% is an alias for Foreach-object

Greetings /\/\o\/\/

Tuesday, February 20, 2007 5:31 AM by MoW
Anonymous comments are disabled