【问题标题】:Why does Powershell say that System.Drawing.Point does not contain method named split.为什么 Powershell 说 System.Drawing.Point 不包含名为 split 的方法。
【发布时间】:2018-12-11 22:21:38
【问题描述】:

即使代码确实运行并成功执行了我想要的操作,以下代码也会引发以下错误。

方法调用失败,因为 [System.Drawing.Point] 没有 包含一个名为“Split”的方法。

我正在尝试拆分以下字符串以仅提取 Y 坐标。

{X=695,Y=665}

代码如下。

$Y_Axis = $postTopScroll2.Split('=')[-1]     
write-host $Y_Axis # 665}

$Y_Axis2 = $postTopScroll2.Split('}')[0]     
Write-Host $Y_Axis2 # 665

我在网上找不到这方面的任何信息。

【问题讨论】:

  • 您看到的是对象的格式化字符串表示 - 使用$postTopScroll2.Y 获取Y 属性的值
  • 因为System.Drawing.Point类没有名为Split的方法。

标签: string powershell split


【解决方案1】:

似乎根据您的帖子 $postTopScroll2 是 System.Drawing.Point https://msdn.microsoft.com/en-us/library/system.drawing.point(v=vs.110).aspx

看起来您不需要进行任何拆分,因为它已经具有 X 和 Y 的属性

[System.Drawing.Point]$postTopScroll2 = [System.Drawing.Point]::new(11,99)
$Y_Axis = $postTopScroll2.y
write-output $Y_Axis

返回 99

【讨论】:

    猜你喜欢
    • 2018-11-19
    • 1970-01-01
    • 2015-09-28
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2012-07-26
    相关资源
    最近更新 更多