如何在 PowerShell 中比较两个字符串对象的内容 [英] How to compare the contents of two string objects in PowerShell

查看:107
本文介绍了如何在 PowerShell 中比较两个字符串对象的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PowerShell 中,我有一个字符串对象数组,我有一个包含字符串对象的对象.在 Java 中,您可以执行 .equals(aObject) 来测试字符串值是否匹配,而执行 == 测试两个对象是否引用内存中的相同位置.

In PowerShell I have an array of string objects, and I have an object that contains string objects. In Java you can do a .equals(aObject) to test if the string values match, whereas doing a == test if the two objects refer to the same location in memory.

如何在 powershell 中运行等效的 .equals(aObject)?

How do I run an equivalent .equals(aObject) in powershell?

我正在这样做:

$arrayOfStrings[0].Title -matches $myObject.item(0).Title

它们都具有完全相同的字符串值,但我得到的返回值为 false.有什么建议吗?

These both have the exact same string values, but I get a return value of false. Any suggestions?

推荐答案

你想做的$arrayOfString[0].Title -eq $myPbiject.item(0).Title

-match 用于正则表达式匹配(第二个参数是正则表达式)

-match is for regex matching ( the second argument is a regex )

这篇关于如何在 PowerShell 中比较两个字符串对象的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆