使用 powershell 拆分字符串以获取第一个和最后一个元素 [英] Split a string with powershell to get the first and last element
本文介绍了使用 powershell 拆分字符串以获取第一个和最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果你这样做:git describe --long
If you do: git describe --long
你得到:0.3.1-15-g3b885c5
这就是上面字符串的含义:
Thats the meaning of the above string:
Tag-CommitDistance-CommitId (http://git-scm.com/docs/git-描述)
Tag-CommitDistance-CommitId (http://git-scm.com/docs/git-describe)
如何拆分字符串以获取第一个 (Tag) 和最后一个 (CommitId) 元素?
How would you split the string to get the first (Tag) and last (CommitId) element?
推荐答案
通过使用 String.split()
使用 count 参数来管理 commitid 中的破折号:
By using String.split()
with the count parameter to manage dashes in the commitid:
$x = "0.3.1-15-g3b885c5"
$tag = $x.split("-",3)[0]
$commitid = $x.split("-",3)[-1]
这篇关于使用 powershell 拆分字符串以获取第一个和最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文