如何解决需要帮助的是获取子字符串
| 我有格式的字符串\"<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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。