Replace , case insensitive

Welcome Forums General PowerShell Q&A Replace , case insensitive

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #66787

    Participant
    Points: 1
    Rank: Member

    Hi All

    I have this , (get-content C:\Settings.xml).Replace("REAL-DB1-QA\DB1", "REAL-DB1-QA") | set-content "C:\Settings.xml" .
    how can I make it ignore the case sensitive so both REAL-DB1-QA\DB1 & REaL-Db1-QA\DB1 , will be replaced ?

  • #66793

    Participant
    Points: 60
    Rank: Member
    (get-content C:\Settings.xml).ToUpper().Replace("REAL-DB1-QA\DB1", "REAL-DB1-QA") | set-content "C:\Settings.xml"
    
    • #66795

      Participant
      Points: 1
      Rank: Member

      Thanks Sam
      worked great .

  • #66804

    Participant
    Points: 10
    Rank: Member

    No need to uppercase all characters, '-replace' is not case-sensitive.

    (get-content C:\Settings.xml) -replace 'REAL-DB1-QA\\DB1','REAL-DB1-QA' | 
    set-content 'C:\Settings.xml'
    
    • #66972

      Participant
      Points: 1
      Rank: Member

      I changed it to \\ because I got errors on escape characters , but it didn't help with the case sensitive issue (only after adding .ToUpper() it was working ) . maybe I will give it another try .

The topic ‘Replace , case insensitive’ is closed to new replies.