Tuesday, 8 November 2011

Show-UnicodeCharacters.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script, a re-implementation of an MSDN sample, shows the  
  4.     Unicode details of a unicode character, using PowerShell. 
  5. .DESCRIPTION 
  6.     This script re-implements a simple MSDN script that takes a Unicode Character 
  7.     and uses CharUnicodeInfo class to get details of that character, which are then 
  8.     displayed. 
  9. .NOTES 
  10.     File Name  : Show-UnicodeCharacters.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2011/11/show-unicodecharactersps1.html 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.charunicodeinfo.aspx
  18. .EXAMPLE 
  19.      Psh > .\show-unicodecharacters.ps1 
  20.                                             c    Num    Dig   Dec    UnicodeCategory 
  21.     U+0061 LATIN SMALL LETTER A             a    -1      -1    -1    LowercaseLetter 
  22.     U+0393 GREEK CAPITAL LETTER GAMMA       Γ    -1      -1    -1    UppercaseLetter 
  23.     U+0039 DIGIT NINE                       9    9       9     9     DecimalDigitNumber 
  24.     U+00B2 SUPERSCRIPT TWO                  ²    2       2     -1    OtherNumber 
  25.     U+00BC VULGAR FRACTION ONE QUARTER      ¼    0.25    -1    -1    OtherNumber 
  26.     U+0BEF TAMIL DIGIT NINE                 ௯    9      9     9     DecimalDigitNumber 
  27.     U+0BF0 TAMIL NUMBER TEN                 ௰    10     -1    -1     OtherNumber 
  28.     U+0F33 TIBETAN DIGIT HALF ZERO          ༳    -0.5    -1    -1     OtherNumber 
  29.     U+2788 CIRCLED SANS-SERIF DIGIT NINE    ➈    9       9    -1     OtherNumber 
  30. #> 
  31.  
  32. # Helper Function 
  33. Function PrintProperties { 
  34.   param ($char
  35.   $fmtstring = " {0,-5}  {1,-8}  {2,-9}  {3,-9}  {4,-9}" 
  36.   $a = $char 
  37.   $b = [System.Globalization.CharUnicodeInfo]::GetNumericValue( $char
  38.   $c = [System.Globalization.CharUnicodeInfo]::GetDigitValue( $char )  
  39.   $d = [System.Globalization.CharUnicodeInfo]::GetDecimalDigitValue( $char
  40.   $e = [System.Globalization.CharUnicodeInfo]::GetUnicodeCategory( $char
  41.   $fmtstring -f $a, $b, $c, $d, $e 
  42. }  
  43. "                                        c      Num      Dig        Dec         UnicodeCategory"  
  44. "U+0061 LATIN SMALL LETTER A            "  + (PrintProperties  "a"
  45. "U+0393 GREEK CAPITAL LETTER GAMMA      "  + (PrintProperties  ([Char] 0x0393) ) 
  46. "U+0039 DIGIT NINE                      "  + (PrintProperties  "9"
  47.  
  48. "U+00B2 SUPERSCRIPT TWO                 "  + (PrintProperties  $([Char] 0x00B2) ) 
  49.  
  50. "U+00BC VULGAR FRACTION ONE QUARTER     "  + (PrintProperties  $([Char] 0x00BC) ) 
  51. "U+0BEF TAMIL DIGIT NINE                "  + (PrintProperties  $([Char] 0x0BEF) ) 
  52. "U+0BF0 TAMIL NUMBER TEN                "  + (PrintProperties  $([Char] 0x0BF0) ) 
  53. "U+0F33 TIBETAN DIGIT HALF ZERO         "  + (PrintProperties  $([Char] 0x0F33) ) 
  54. "U+2788 CIRCLED SANS-SERIF DIGIT NINE   "  + (PrintProperties  $([Char] 0x2788) ) 

No comments: