Results 1 to 4 of 4

Is there a better way? (There always is.) - HOWTO: Replace repeated text in an array.

Threaded View

  1. #1
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Is there a better way? (There always is.) - HOWTO: Replace repeated text in an array.

    I'm working with Cisco router data. In a router dump, there will be lines that say "interface <some interface_name>".

    I load an array with this:
    arrLocalTemp = FilterRegEx(arrRouterDataNew, "^interface Vlan*")
    FWIW, 'FilterRegEx' is a function I wrote that does what it's name says (I'll include it below, for critique and improvement).

    The array I get will contain every line in my router data pull that starts with "interface Vlan*". But, I don't want every element to start with "interface ".
    Here is my one-line cleanup (is this the best way?):
    arrLocalTemp = Split(Replace(Join(arrLocalTemp, vbCrLf), "interface ", vbNullString), vbCrLf)
    The reason I'm asking is this the most efficient way to do this?

    As promised, here is my FilterRegEx function:
    Function FilterRegEx(arrInput As Variant, Ptn$) As Variant
    Dim regexOne As Object
    Dim inputLine As Variant, Match As Variant, theMatches As Variant
    Dim strToMatch$, strMatches$, arrMatches$()
    Set regexOne = New VBScript_RegExp_55.RegExp
    '
        With regexOne
            .pattern = Ptn
            .Global = True
            For Each inputLine In arrInput
                strToMatch = inputLine
                Set theMatches = .Execute(strToMatch)
                For Each Match In theMatches
                    strMatches = IIf(Len(strMatches), strMatches & vbCrLf & inputLine, inputLine)
                Next
            Next
        End With
        arrMatches = Split(strMatches, vbCrLf)
        FilterRegEx = arrMatches
        strMatches = vbNullString
        Erase arrMatches
    End Function
    Last edited by Rhudi; 02-22-2023 at 03:42 PM. Reason: Typo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Replace a Text in 255 character Array Formula
    By RXcel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2019, 01:47 AM
  2. RE: Can't Get BoSox Lineup to Automatically Time-Stamp and ReSort When New Batter Added
    By justinbelkin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2013, 05:35 PM
  3. [SOLVED] Append data to repeated values with a fixed array to be repeated on value change
    By anchuri_chaitanya in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-06-2011, 12:30 AM
  4. Howto concatenate Array values
    By rwgrietveld in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-22-2008, 01:28 PM
  5. [SOLVED] HowTo:Validation Formula = Array of strings
    By AMDRIT in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-23-2006, 04:55 PM
  6. [SOLVED] Printing text in a repeated cell/row that is longer than repeated
    By Valerie Dyet in forum Excel General
    Replies: 1
    Last Post: 02-12-2006, 11:30 PM
  7. HowTo add a period to front of EVERY text cell in a Excel column
    By adamcollegeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2005, 03:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1