powershell - 在文本文件中交换 last.first 到 first.last

标签 powershell

我正在尝试交换字符串中的两个单词。我目前有一个 txt 文件,其中有一列用户格式为 last.first。我如何将它交换为 first.last

最佳答案

-split 字符串并连接:

$Last,$First = "Lastname.Firstname" -split '\.'
$newString = "$First.$Last"

或使用-replace 重新排列两者:

"Lastname.Firstname" -replace '(\w+)\.(\w+)','$2.$1'

关于powershell - 在文本文件中交换 last.first 到 first.last,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38399360/

相关文章:

powershell - Select-Object返回第一个结果作为我的列名,而不是结果

powershell - 从基于文本的表输出中提取列

windows - 在 Windows PowerShell 中获取日期范围内的文件

powershell - 在 PowerShell 中删除最旧版本的目录

powershell - Nuget Powershell命令-查找安装了特定软件包的项目

Powershell模拟键盘

接受正则表达式组的前瞻部分

powershell - 在Windows上的脚本中的浏览器中打开并播放YouTube

powershell - 为 CSV 文件添加 header

windows - 如何获取可能的 Windows 服务状态列表?