如何在vbscript中的模式后显示文本? [英] How to display text after pattern in vbscript?

查看:61
本文介绍了如何在vbscript中的模式后显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的其他 vbscript,我有一个包含以下文本的文件:

I have a file with the following text as a result of my other vbscript:

              "Name": "stopped"
            "LaunchTime": "2015-02-13<some-text>", 
            "InstanceId": "i-<something>", 
                "Name": "stopped"
            "LaunchTime": "2015-02-13T17:24:11.000Z", 
            "InstanceId": "i-<something>", 
                "Name": "stopped"
            "LaunchTime": "2015-02-12<some-text>", 
            "InstanceId": "i-<something>", 

我想使用 4 个字符作为分隔符 -> ":"(4 个字符)并在其右侧显示所有内容,因此结果如下所示:

I want to use 4 characters as delimiter -> ": " (which is 4 characters) and display everything at the right side of it, so the result will look like this:

"stopped"
"2015-02-13<some-text>", 
"i-<something>", 

"stopped"
"2015-02-13T17:24:11.000Z", 
"i-<something>", 

 "stopped"
"2015-02-12<some-text>", 
"i-<something>", 

我如何使用 vbscript 完成这样的事情?似乎在 bash、perl、awk 甚至 linux 命令行中,类似的事情是如此简单.有没有简单的方法来做到这一点?我正在考虑拆分,但我不知道该怎么做.

How can I accomplish such thing using vbscript? It seems that in bash, perl, awk and even linux command line things like that are so simple. Is there an easy way to do it? I was looking into split but I can't figure it out how to do it.

谢谢

推荐答案

最简单的方法是 Split : 处的行(冒号后跟一个空格)并显示第二个字段(索引1) 结果数组:

The simplest way would be to Split the lines at : (a colon followed by a space) and display the second field (index 1) of the resulting array:

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("C:\path\to\your.txt")
Do Until f.AtEndOfStream
  line = f.ReadLine
  If InStr(line, ": ") > 0 Then WScript.Echo Split(line, ": ", 2)(1)
Loop
f.Close

这篇关于如何在vbscript中的模式后显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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