zhaomc520 发表于 2007-1-17 12:37:00

<p>很好使,谢谢楼主帮忙</p><p>小弟会更加努力学习的,有一天也能帮助一下别人是我努力的目标。呵呵 </p>

dwg001 发表于 2007-1-17 13:09:00

<p><strong><font color="#ff0000">mccad:</font></strong></p><p><strong><font color="#ff0000">请问怎么在autocad R2004下运行怎么无任何动作?</font></strong></p>

loulans 发表于 2007-2-23 22:33:00

??

nic 发表于 2007-4-21 13:25:00

版主,可否按照特定的特征进行提取字串而非替换呢?也即不用replace方法,只是复制出来特征字串的方法是何,请指点一下。谢谢。

lennie 发表于 2007-11-15 16:21:00

mccad,这个好像不行啊

lennie 发表于 2007-11-15 16:28:00

<br/>Public Function Mtext2text(MyString As String) As String<br/>&nbsp;&nbsp;&nbsp; Dim objRegExp As New RegExp<br/>&nbsp;&nbsp;&nbsp; Dim objMatch As Match<br/>&nbsp;&nbsp;&nbsp; Dim colMatches As MatchCollection<br/>&nbsp;&nbsp;&nbsp; Dim RetStr As String<br/>&nbsp;&nbsp;&nbsp; objRegExp.IgnoreCase = False&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 如果设为True, 则当指定,或时,将不会区分大小写判断。<br/>&nbsp;&nbsp;&nbsp; objRegExp.Global = True<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '替换\\字符<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\\\\\</a>"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, Chr(1))<br/>&nbsp;&nbsp;&nbsp; '替换\{字符<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\</a>{"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, Chr(2))<br/>&nbsp;&nbsp;&nbsp; '替换\}字符<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\</a>}"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, Chr(3))<br/>&nbsp;&nbsp;&nbsp; '删除段落缩进格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\pi</a>(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除制表符格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\pt</a>(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除堆迭格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\S(.[^;]*)(\\^|#|\\\\</a>)(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除字体、颜色、字高、字距、倾斜、字宽、对齐格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "(<a>\\\\F|\\\\f|\\\\C|\\\\H|\\\\\T|\\\\Q|\\\\W|\\\\A</a>)(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除下划线、删除线格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "(<a>\\\\L|\\\\O|\\\\l|\\\\o</a>)"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除不间断空格格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\</a>~"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除换行符格式<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "<a>\\\\P</a>"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除换行符格式(针对Shift+Enter格式)<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "\n"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; '删除{}<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = "({|})"<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '替换回<a href="file://\\,\{,\">\\,\{,\</a>}字符<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = Chr(1)<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "\\")<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = Chr(2)<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "{")<br/>&nbsp;&nbsp;&nbsp; objRegExp.Pattern = Chr(3)<br/>&nbsp;&nbsp;&nbsp; MyString = objRegExp.Replace(MyString, "}")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Mtext2text = MyString<br/>End Function<br/>

lennie 发表于 2007-11-15 16:28:00

本帖最后由 作者 于 2007-11-15 16:32:18 编辑

附上VBA代码

Public Function Mtext2text(MyString As String) As String
    Dim objRegExp As New RegExp
    Dim objMatch As Match
    Dim colMatches As MatchCollection
    Dim RetStr As String
    objRegExp.IgnoreCase = False       ' 如果设为True, 则当指定,或时,将不会区分大小写判断。
    objRegExp.Global = True
   
    '替换\\字符
    objRegExp.Pattern = "\\\\\\\\"
    MyString = objRegExp.Replace(MyString, Chr(1))
    '替换\{字符
    objRegExp.Pattern = "\\\\{"
    MyString = objRegExp.Replace(MyString, Chr(2))
    '替换\}字符
    objRegExp.Pattern = "\\\\}"
    MyString = objRegExp.Replace(MyString, Chr(3))
    '删除段落缩进格式
    objRegExp.Pattern = "\\\\pi(.[^;]*);"
    MyString = objRegExp.Replace(MyString, "")
    '删除制表符格式
    objRegExp.Pattern = "\\\\pt(.[^;]*);"
    MyString = objRegExp.Replace(MyString, "")
    '删除堆迭格式
    objRegExp.Pattern = "\\\\S(.[^;]*)(\\^|#|\\\\)(.[^;]*);"
    MyString = objRegExp.Replace(MyString, "")
    '删除字体、颜色、字高、字距、倾斜、字宽、对齐格式
    objRegExp.Pattern = "(\\\\F|\\\\f|\\\\C|\\\\H|\\\\\T|\\\\Q|\\\\W|\\\\A)(.[^;]*);"
    MyString = objRegExp.Replace(MyString, "")
    '删除下划线、删除线格式
    objRegExp.Pattern = "(\\\\L|\\\\O|\\\\l|\\\\o)"
    MyString = objRegExp.Replace(MyString, "")
    '删除不间断空格格式
    objRegExp.Pattern = "\\\\~"
    MyString = objRegExp.Replace(MyString, "")
    '删除换行符格式
    objRegExp.Pattern = "\\\\P"
    MyString = objRegExp.Replace(MyString, "")
    '删除换行符格式(针对Shift+Enter格式)
    objRegExp.Pattern = "\n"
    MyString = objRegExp.Replace(MyString, "")
    '删除{}
    objRegExp.Pattern = "({|})"
    MyString = objRegExp.Replace(MyString, "")
   
    '替换回\\,\{,\}字符
    objRegExp.Pattern = Chr(1)
    MyString = objRegExp.Replace(MyString, "\\")
    objRegExp.Pattern = Chr(2)
    MyString = objRegExp.Replace(MyString, "{")
    objRegExp.Pattern = Chr(3)
    MyString = objRegExp.Replace(MyString, "}")
   
    Mtext2text = MyString
End Function

助淫为乐 发表于 2007-11-16 08:42:00

BPE 发表于 2007-11-16 10:49:00

明经高手多到数不清,我也有个想大家帮编的,不知有高手帮下菜人吗?

无痕 发表于 2007-11-16 19:58:00

助淫为乐发表于2007-11-16 8:42:00static/image/common/back.gif用WCMATCH配合通配符进行替换不也一样?

<p>不一样,试试看就知道了。你要能用WCMATCH配合通配符 写一个出来,我给你加分</p>
页: 1 [2] 3 4 5
查看完整版本: 在VLISP中使用正则表达式(一)取多行文字中的有用内容