问题描述
|
我有格式的字符串
\"<testname>$ns1$,$NS2$,$NS3$</testname>\"
我需要将字符串设为\"$ns1$,$NS3$\"
可能会因为
\" <testname>$ns1$,$NS3$</testname>\"
提前致谢
Excel开发
解决方法
因此,要重新构造您的问题,您想要切出一个子字符串,该子字符串在第一个\“> \”之后开始,并在第一个\“之前结束
在进入VBA之前,我们先尝试找到一个公式
cell [A1] contains text \"<tag>Content</tag>\"
所以
Formula Result Comment
1) =FIND(\">\",A1,1)+1 6 1st char of inner
2) =FIND(\"</\",A1)-1 12 last char of inner
3) =FIND(\"</\",A1)-FIND(\">\",1)-1 7 length of inner
结合1和3
4) =MID(A1,FIND(\">\",1)+1,FIND(\"</\",A1;1)-1)
Content the inner
意味着您可以在不使用VBA的情况下切出内部.....但我们当然也可以提供出色的VBA :-))
希望能有所帮助
,Function GetInnerTag(byval value as string) as string
dim offset1 as integer
dim offset2 as integer
offset1= instr(1,value,\">\")
\'If the index of the first greater-than
\'is less than one,return an empty string
if offset1 <1 then
GetInnerTag=\"\"
Exit Function
end if
offset2=instr(offset1+1,\"<\")
\'If the index of the first less-than
\'less than one,return \"\"
if offset2 <1 then
GetInnerTag=\"\"
Exit Function
end if
GetInnerTag=mid(value,offset1+1,(offset2-offset1-1))
End Function