Hello.
I need to know is there case-insensitive option for this:
$files=Get-ChildItem "D:\temp\"* -include *.resx -recurse $files| ForEach-Object{ $xml=[xml](Get-Content $_) $xml.selectNodes('//data/value[contains(.,"text")]')| ForEach-Object{$_.'#text' = ($_.'#text' -replace 'text','foo1') } $xml.Save($_) }I want to do replace in xml resx files with Powershell. This script work only like case-sensitive("text" must match exactly).Can I modify this script to make case-insensitive replacement?Thank you in forward.
Use the Replace() method of a string object
$_.'#text'.Replace('text','fool')
It's case-sensitive already.
You aren't using the -contains operator; I'm not familiar with the [contains] syntax you're using. That looks to be part of XPath, and so it would already be case-sensitive. But it isn't the PowerShell -contains operator, if that's what you're thinking. PowerShell isn't processing that; XML is.
Thank you for reply.
Now I need to count entries which matched by pattern in resx xml files. In output I need integer value of matched entries by pattern inside //data/value xpath (and maybe also //data/comment for include also comments).
Maybe I can do something like that?
var counter = 0 get-childitem "D:\temp\"* -include *.resx -recurse -force | foreach-object { $xml=[xml](get-content $_.FullName) $xml.selectNodes('//data/value[text()]') | foreach-object{$_.'#text' -match 'text' if($matches.count != 0) { counter += $matches.count } } | select counter }
or something like that:
var counter = 0 get-childitem "D:\temp\"* -include *.resx -recurse -force | select-xml -xpath "//data/value" | foreach-object { $_.node.InnerXML -match '[\s\S]*?text[\s\S]*?' if($matches.count != 0) { counter += $matches.count } } | select counter
$matches.count will include a count of all matches made from the last -match operation, yes.