在powershell中的分隔符之后/之前截断字符串中的文本 [英] Cut off text in string after/before separator in powershell

查看:86
本文介绍了在powershell中的分隔符之后/之前截断字符串中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我想要做的:我想制作一个小的 powershell 脚本,它获取我的音乐库中的每个文件,然后对其进行哈希求和并将其写入文件中,如下所示:

Ok so here is what I'm trying to do: I want to make a little powershell script that takes each file of my music library and then does a hash sum of it and writes that into a file like so:

test.txt ; 131 136 80 89 119 17 60 123 210 121 188 42 136 200 131 198

现在,当我启动脚本时,我需要它首先将我的音乐库与已经存在的值进行比较,但为此我只想切断 ; 之后的所有内容,以便它可以将文件名与文件名(或文件路径)...但我对如何做到这一点感到困惑,尝试用

Now when I start the script I need it to first compare my music library with the already existing values but for this I just want to cut off everything after the ; so that it can compare filename against filename (or filepath)... but I'm stumped at how to do that, tried replacing with

$name = $name -replace ";*",""

不行...

试图过滤...不知道如何 D:

tried to filter... don't know how D:

非常感谢您的帮助.

另外,如果你认为我使用了错误的编码语言,请告诉我什么会更好,只是我只使用过 C 和 powershell

Also if you think I'm using the wrong coding language, tell me and what would be better, it's just I only ever used C and powershell

推荐答案

$pos = $name.IndexOf(";")
$leftPart = $name.Substring(0, $pos)
$rightPart = $name.Substring($pos+1)

在内部,PowerShell 使用 String班级.

Internally, PowerShell uses the String class.

这篇关于在powershell中的分隔符之后/之前截断字符串中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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