How to replace string case insensitive?

Hello,

how would I do case-insensitive string replacing?

<!–StartFragment –>

`Desktop> 'aaa'.Replace('aaa', 'bbb', 'OrdinalIgnoreCase')` `Cannot find an overload for "Replace" and the argument count: "3".` `At line:1 char:1` `+ 'aaa'.Replace('aaa', 'bbb', 'OrdinalIgnoreCase')` `+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~` `+ CategoryInfo : NotSpecified: (:) [], MethodException` `+ FullyQualifiedErrorId : MethodCountCouldNotFindBest`
in C# the code works:
`foreach (string badString in badStrings)` ` fileName = fileName.Replace($".{badString}.", ".", StringComparison.OrdinalIgnoreCase);`
edit:
I found this workaround:
` foreach ($badString in $badStrings)`
` {`
` $badString = [Regex]::Escape($badString)`
` $fileName = $fileName -replace ('\.' + $badString + '\.'), '.'`
` }`
<!--EndFragment -->
# Case-Insensitive
PS> 'AAAaaaBBBCDeFg' -replace 'a','*'
******BBBCDeFg
# Case-Sensitive
PS> 'AAAaaaBBBCDeFg' -creplace 'a','*'
AAA***BBBCDeFg

Thanks for the reply, the -replace operator uses regex which is problematic because my input strings might contain regex syntax.

I found my problem finally, my C# code is .NET Core based and apparently this overload does not exist in .NET Framework based PowerShell. I can use [Regex]::Escape to escape my input strings.

'Hi'.replace('h','i')
Hi

'Hi'.replace('H','i')
ii

'hi'.replace('.','j')
hi