2015-04-07 125 views
1

在此处寻找帮助。我有一个文本字符串,如:如果文本字符串包含某些单词,请将这些单词包裹在span标记中

> ...And The World Laughs With You (feat Thom Yorke) 

随着vbscript,如果文本串中有"(feat ",我想包装在span标记整个括号中的文字。
所以,上面的例子看起来像:

> ...And The World Laughs With You <span>(feat Thom Yorke)</span> 

希望这是有道理的,谢谢你提前的帮助!

干杯,
德鲁

+0

你的问题是什么? –

回答

2

与此逻辑尝试。

 dim str 
    str = "And The World Laughs With You (feat Thom Yorke)" 

    If INSTR(str,"(feat ") > -1 Then 
     str = REPLACE(str,"(feat ","<span>(feat ") 
     str = REPLACE(str,")",")</span>") 
    End If 

    Response.Write("Result:- " + str) 
+0

这不是VBScript。 –

+0

@ Ekkehard.Horner - 我已将代码更改为vbscript。 –

0

见例子。

Set Arg = WScript.Arguments 
set WshShell = createObject("Wscript.Shell") 
Set Inp = WScript.Stdin 
Set Outp = Wscript.Stdout 

Sub ReplaceCmd 
    'Remove^from quoting command line. Quote, ampersand and brackets 
    Pttn = Replace(Arg(2), "^(", "(") 
    Pttn = Replace(Pttn, "^)", ")") 
    Pttn = Replace(Pttn, "^&", "&") 
    Pttn = Replace(Pttn, "^""", """") 
    Set regEx1 = New RegExp 
    If Instr(LCase(Arg(1)), "i") > 0 then 
     regEx1.IgnoreCase = True 
    Else 
     regEx1.IgnoreCase = False 
    End If 
    regEx1.Global = False 
    regEx1.Pattern = Pttn 
    Do Until Inp.AtEndOfStream 
     Line=Inp.readline 
     Line = RegEx1.Replace(Line, Arg(3)) 
     outp.writeline Line 
    Loop 
End Sub 

要使用cscript scriptname <infile >outfile

更换

filter replace {i|n} expression replace 
filter repl {i|n} expression replace 

发现和使用正则表达式替换文本。

也用于从文件中提取子字符串。

表达式中的&符号和括号内必须使用脱字符。不要逃脱插入。使用十六进制代码\ x22作为引号。

SearchOptions

我 - 忽略大小写 N - 无 表达

正则表达式参考

更换

替换的文本。使用$ 1,$ 2,$ ...,$ N来替换字符串中指定的子场比赛

filter replace i "=" "No equal sign" < "%systemroot%\win.ini" 

这种搜索方括号内的文字和替换猫行后跟内的文本括号

Filter replace i "^\[^(.*^)\]" "cat$1" < %windir%\win.ini 

这将搜索任何文本并从第11个字符打印到行尾。

Filter replace i "^.{10}^(.*^)$" "$1" < %windir%\win.ini 

此搜索的CSV文件,并打印所述第二和第四场

Filter replace i "^.+,^(.+^),.+,^(.+^)$" "$1,$2" < csv.txt 
+0

@Jinesh Jain你很好,你从我的复制你的答案。 – Serenity

相关问题