【问题标题】:Odd school assignment, about displaying emojis in powershell奇怪的学校作业,关于在 powershell 中显示表情符号
【发布时间】:2021-05-25 09:59:39
【问题描述】:

我很高兴获得在 Powershell 中发布表情符号的任务,唯一的问题是它们必须在同一行,而且一共有三个。这是我的第一个任务,我们之前没有在这门学科上进行过教学,所以在谷歌搜索和搜索 YouTube 之后,我最好的镜头是下面这个,但是,它带有一些错误,说价值太高或价值太低。

完整的错误文本:使用“2”参数调用“ToInt32”的异常:“对于 UInt32,该值太大或太小。” 在 C:\Users\EG\Downloads\Herningsholm\Powershell H1\Hardware Information.ps1:3 char:5 $ UnicodeInt = [System.Convert] :: toInt32 ($ StrippedUnicode, 16) CategoryInfo: NotSpecified: (:) [], MethodInvocationException FullyQualifiedErrorId: 溢出异常

$FullUnicode = ('U+1F60E') + ('U+1F436') + ('U+1F642')
$StrippedUnicode = $FullUnicode -replace 'U\+',''
$UnicodeInt = [System.Convert]::toInt32($StrippedUnicode,16)
[System.Char]::ConvertFromUtf32($UnicodeInt)

【问题讨论】:

  • 请将您的完整错误文本添加到您的问题中。
  • @Lee_Dailey 我运行该代码并得到以下错误“异常调用“ToInt32”与“2”参数:“对于 UInt32,值太大或太小。”。我认为他指的是同样的错误。
  • 我重复一遍...... 请将您的完整错误文本添加到您的问题中。

标签: powershell powershell-ise


【解决方案1】:

试试这个: 完整的表情符号列表 > here

# saves unicode for each emoji https://unicode.org/emoji/charts/full-emoji-list.html
$FullUnicode0 = 'U+1F606'
$FullUnicode1 = 'U+1F605'
$FullUnicode2 = 'U+1F605'

# removes the U+ bit
$StrippedUnicode0 = $FullUnicode0 -replace 'U\+',''
$StrippedUnicode1 = $FullUnicode1 -replace 'U\+',''
$StrippedUnicode2 = $FullUnicode2 -replace 'U\+',''

# Converts the value of the specified object to a 32-bit signed integer
$UnicodeInt0 = [System.Convert]::toInt32($StrippedUnicode0,16)
$UnicodeInt1 = [System.Convert]::toInt32($StrippedUnicode1,16)
$UnicodeInt2 = [System.Convert]::toInt32($StrippedUnicode2,16)

# Converts the specified Unicode code point into a UTF-16 encoded string so that you have an emoji
$Emoji0 = [System.Char]::ConvertFromUtf32($UnicodeInt0)
$Emoji1 = [System.Char]::ConvertFromUtf32($UnicodeInt1)
$Emoji2 = [System.Char]::ConvertFromUtf32($UnicodeInt2)

write-host "$($Emoji0), $($Emoji1), $($Emoji2)" 

【讨论】:

  • 非常感谢,这绝对有帮助!这实际上让我更好地理解了应该发生的事情,非常感谢。 :)
  • 很高兴这对您有所帮助,并解决了问题。如果对您有帮助,您可以将答案标记为已回答。
  • 我以前从未使用过这个网站,我的朋友今天才向我推荐了它。我在哪里将其标记为已回答?
  • 好了,完成了,你能解释一下这三个不同的东西是做什么的吗?最后一个“写主机”很简单,但我想知道其余的内容是什么
  • cmets 添加到脚本中
猜你喜欢
  • 2023-03-11
  • 2014-03-27
  • 1970-01-01
  • 2011-12-23
  • 1970-01-01
  • 1970-01-01
  • 2016-02-27
  • 2021-07-04
  • 1970-01-01
相关资源
最近更新 更多