gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:36:20 27 4
gpt4 key购买 nike

我正在尝试交换字符串中的两个单词。我目前有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com