如何在 PowerShell 中将字符串内容拆分为字符串数组? [英] How to split a string content into an array of strings in PowerShell?
本文介绍了如何在 PowerShell 中将字符串内容拆分为字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,其中的电子邮件地址以分号分隔:
I have a string that has email addresses separated by semi-colon:
$address = "foo@bar.com; boo@bar.com; zoo@bar.com"
如何将其拆分为如下结果的字符串数组?
How can I split this into an array of strings that would result as the following?
[string[]]$recipients = "foo@bar.com", "boo@bar.com", "zoo@bar.com"
推荐答案
从 PowerShell 2 开始,简单:
As of PowerShell 2, simple:
$recipients = $addresses -split "; "
请注意,右侧实际上是一个不区分大小写的正则表达式,而不是简单的匹配.使用 csplit
强制区分大小写.请参阅about_Split了解更多详情.
Note that the right hand side is actually a case-insensitive regular expression, not a simple match. Use csplit
to force case-sensitivity. See about_Split for more details.
这篇关于如何在 PowerShell 中将字符串内容拆分为字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文