• 将该字符连续部分替换为指定的其它任意字符


    指定某字符,并将该字符连续部分数目替换为指定的1个字符。

    如调用:RegexReplace("ABC%%%%%DE%%FGHIJK%%","%","*")

    结果将得到:ABC*DE*FGHIJK*

    '传入:%%%%exe%%%%%%%.dll
    '结果:%exe%.dll
    'by Gary 20130308
    Private Function RegexReplace(ByVal Expression As String, Optional ByVal Find As Variant = "%", Optional ByVal Replace As Variant = "%") As String On Error GoTo ErrHandler Dim rtStr As String, arrExpression() As String Dim I As Integer If Len(Trim(Expression)) <= 0 Then Exit Function arrExpression() = Split(Expression, Find) '如: 传入的 Expression 变量值为:%exe%%txt%%% 得到的结果应该为:%exe%txt% '当第一个字符为 Find 传入的字符时,不会加在字符串中,会被过滤掉。此句就解决了这个问题 If Left(Expression, 1) = Find Then rtStr = Find For I = 0 To UBound(arrExpression) If arrExpression(I) <> "" Then If I = UBound(arrExpression) Then rtStr = rtStr & arrExpression(I) Else rtStr = rtStr & arrExpression(I) & Find End If End If Next Erase arrExpression() RegexReplace = rtStr Exit Function ErrHandler: RegexReplace = "" End Function
  • 相关阅读:
    servlet
    grep命令
    sort排序命令
    shell脚本面试
    查看远端的端口是否通畅3个简单实用案例!
    mail命令
    linux系统优化的方法
    shell数组
    shell函数介绍语法说明及基本例子
    循环结构的多个控制命令对比与实际案例
  • 原文地址:https://www.cnblogs.com/garyxiao/p/2949401.html
Copyright © 2020-2023  润新知