- function Asc{
- param([string]$Chars)
- $ecode=[System.Text.Encoding]::GetEncoding('GB2312')
- $Chars.ToCharArray()|%{
- [byte[]]$bytes=$ecode.GetBytes($_)
- if($ecode.GetByteCount($_) -eq 2){$bytes[0]*256+$bytes[1]-65535}else{$bytes[0]}
- }
- }
- function Chr{
- param([int[]]$Codes)
- $asccode=[System.Text.Encoding]::GetEncoding('GB2312')
- $Codes|%{
- [byte[]]$bytes=[System.BitConverter]::GetBytes($_)
- if($_ -le 0 -or $_ -gt 255){
- [byte[]]$chrbyte=New-Object byte[] 2
- $chrbyte[0]=$bytes[1]
- $chrbyte[1]=$bytes[0]
- }else{
- [byte[]]$chrbyte=New-Object byte[] 1
- $chrbyte[0]=$bytes[0]
- }
- $asccode.GetString($chrbyte)
- }
- }
-
-
- chr (asc '你好')
复制代码 这个代码有问题,返回值不对,应该返回你好,但返回错了,不知道哪里写的有问题? |