locked
Removing text from a string based on an array RRS feed

  • Question

  • I'm having to sanitize some data, and I've managed to trim out nearly everything from a string that I need gone except a certain pair of words that are only consistent in that there's a specific set of them:

    City of 
    Village of 
    County of 
    Town of 
    etc.

    Example string: City of Denver

    I've already set up an array and a method to test against it:

        $cityIdentifier = @("City of ","Village of ","County of ","Town of ")
        if ($null -ne ($cityIdentifier | ? { $parsedCity -match $_ }) {
          #magic happens here
        }
    
    But I'm having trouble finding a way to remove the text from the string based on what's found in the array. (when I do Internet searches for this, I turn up lots of ways to add or remove strings from arrays, but nothing on removing sections of a string based on the array)

    My question is, what do I put in this if statement in place of "#magic happens here" to make this happen?

    Tuesday, June 13, 2017 6:26 PM

Answers