返回列表 发帖

[问题求助] VBS去掉字符串中所有尖括号<...>之间的字符

本帖最后由 pcl_test 于 2016-7-19 12:23 编辑

比如我的字符串是
22233< /b>3333aa
   <u8fj>d93j
3

注意带换行符的,如果去掉所有的<...>其他不变返回新字符,就是把所有的<...>用空字符串替代,应该怎么写呀

我想放在VBS里,批处理写的如何放进去用也请说下,THX

使用正则来处理的一个例子,如果内容在文档中,自己可稍做修改,另:这里不替换“<>”,也就是当尖括号中内容为空时,不进行替换...
测试代码:
dim test(4),regEx
test(0)="22233< /b>3333aa"
test(1)="<u8fj>d93j"
test(2)="3"
test(3)="OK<this is a test>test this"
test(4)="test here<>test here"
for i=0 to 4
Mystr=Mystr & vbcrlf & test(i)
next
msgbox "处理前字符:"&Mystr
Set regEx = New RegExp   
regEx.Pattern ="<[^<]{1,}>"
regEx.IgnoreCase = True
regEx.Global = True        
msgbox regEx.replace(Mystr,"")       COPY

TOP

嗯,用正则最好。

好像regEx.Pattern = "<[^>].*>"也可以。

TOP

codehtml_s=split(yaojia_shuju,">")
for t=0 to ubound(codehtml_s)
if instr(codehtml_s(t),"<")<>0 then
codehtml_m=split(codehtml_s(t),"<")(0)
else
codehtml_m=codehtml_s(t)
end if
codehtml_all=codehtml_all&codehtml_m
next
这是我写的,正则还没学!

[ 本帖最后由 sexfio 于 2009-5-6 08:56 编辑 ]

TOP

replace <>, 怪异字符0

replace <,怪异字符
replace >,怪异字符

split(str,怪异字符)

循环将偶数下标取出来合并。

replace 怪异字符0,<>

TOP

返回列表