- 积分
- 348
- 明经币
- 个
- 注册时间
- 2008-5-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2009-10-3 12:03:00
|
显示全部楼层
转过去的链接中大家讨论得已经比较详细了,我比较喜欢mccad大虾的思路,但是我觉得他所提供的函数中有一点点瑕疵,最起码我用
"\A1;\{{\H1.6x;A}\P{\LB}\P{\H1.6x;C;}\P\pi0.999306,l2.99792,t7;{\fCorbel|b0|i0|c0|p34;D}\P\pi0,l0,tz;{\C1;E}\PF?\PG\\\Ph{\H0.7x;\S1/2;}\PJ{\H0.7x;\S2^;}\PK{\H0.7x;\S^2;}|\PL"
这个字符串作核试验的时候就不完全正确,而且稍显繁复,所以我重新总结了一下,得出下面的两个函数,请众位同好不吝指正
第一个是用RegExp来替换的自定义函数- Public Function ReplaceByRegExp(ByVal Mystrig As String, ByVal TxtFind As String, ByVal TxtReplace As String)
- Dim RE As Object
- Set RE = ThisDrawing.Application.GetInterfaceObject("Vbscript.RegExp")
-
- RE.IgnoreCase = False
- RE.Global = True
-
- RE.Pattern = TxtFind
- ReplaceByRegExp = RE.Replace(Mystrig, TxtReplace)
- Set RE = Nothing
-
- End Function
第二个是用来清除多行字格式的函数- Public Function MtextStringClearFormat(ByVal MyString As String) As String
- MyString = ReplaceByRegExp(MyString, "\\{", Chr(1))
- MyString = ReplaceByRegExp(MyString, "\\}", Chr(2))
- MyString = ReplaceByRegExp(MyString, "\\\", Chr(3))
- MyString = ReplaceByRegExp(MyString, "\\S([^;]*?)(\^|#)([^;]*?);", "$1$3")
- MyString = ReplaceByRegExp(MyString, "\\S([^;]*?);", "$1")
- MyString = ReplaceByRegExp(MyString, "(\\P|\\O|\\o|\\L|\\l|\{|\})", "")
- MyString = ReplaceByRegExp(MyString, "\\[^;]*?;", "")
- MyString = ReplaceByRegExp(MyString, "\x01", "{")
- MyString = ReplaceByRegExp(MyString, "\x02", "}")
- MyString = ReplaceByRegExp(MyString, "\x03", "")
- MtextStringClearFormat = Trim(MyString)
- End Function
最后写一个测试过程- Sub TEST()
- Dim TxtOld As String
- Dim TxtNew As String
- TxtOld = "\A1;\{{\H1.6x;A}\P{\LB}\P{\H1.6x;C;}\P\pi0.999306,l2.99792,t7;{\fCorbel|b0|i0|c0|p34;D}\P\pi0,l0,tz;{\C1;E}\PF?\PG\\\Ph{\H0.7x;\S1/2;}\PJ{\H0.7x;\S2^;}\PK{\H0.7x;\S^2;}|\PL"
- TxtNew = MtextStringClearFormat(TxtOld)
-
- End Sub
大家再帮我用其它的字符串测试一下,看看是不是有所遗漏或是BUG,谢谢了
|
|