如何在VBScript中从文件路径的中间获取子字符串? [英] How can I get a substring from the middle of a file path in VBScript?
问题描述
我在VBScript中具有以下字符串:
I have the following string in VBScript:
myPath = "C:\Movies\12 Monkeys\12_MONKEYS.ISO"
路径C:\ Movies \总是一样.因此,这里以另一条路径为例:
The path C:\Movies\ is always going to be the same. So here is another path as an example:
myPath = "C:\Movies\The Avengers\DISC_1.ISO"
我的问题是,如何仅提取影片文件夹名称,因此在以上示例中我将得到:
My question is, how can I pull only the movie folder name, so in the above examples I would get:
myMovie = "12 Monkeys"
myMovie = "The Avengers"
有没有办法与此一起使用RegEx?还是我应该做一些子字符串和索引调用?最简单的方法是什么?
Is there a way to use RegEx with this? Or should I just do some substring and index calls? What is the easiest way to do this?
推荐答案
请考虑以下代码:
arrPathParts = Split(myPath, "\");
myMovie = arrPathParts(2);
在分隔符为反斜杠字符的位置分割字符串.拆分字符串将返回一个字符串数组.您的电影是字符串数组中的第三项.
Split the string where the delimiter is the backslash character. Splitting a string returns an array of strings. Your movie is the third item in the array of strings.
这篇关于如何在VBScript中从文件路径的中间获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!