Character codes: Difference between revisions

Content added Content deleted
(PowerShell implementation)
Line 277: Line 277:
<lang php>echo ord('a'), "\n"; // prints "97"
<lang php>echo ord('a'), "\n"; // prints "97"
echo chr(97), "\n"; // prints "a"</lang>
echo chr(97), "\n"; // prints "a"</lang>

=={{header|PowerShell}}==
PowerShell does not allow for character literals directly, so to get a character one first needs to convert a single-character string to a char:
<lang powershell>$char = [char] 'a'</lang>
Then a simple cast to int yields the character code:
<lang powershell>$charcode = [int] $char # => 97</lang>
This also works with Unicode:
<lang powershell>[int] [char] '☺' # => 9786</lang>
For converting an integral character code into the actual character, a cast to char suffices:
<lang powershell>[char] 97 # a
[char] 9786 # ☺</lang>


=={{header|Python}}==
=={{header|Python}}==