Search for color string in powershell -
i have powershell code. how can search characters within richtextbox
have color formatting? or color @ all?
let's red background example. have highlighted portion of text , find characters.
currently, have search text only. code example:
function example-search { $index = $resultbox.find($searchtext, $resultbox.selectionstart + $resultbox.selectedtext.length, [system.windows.forms.richtextboxfinds]::none) if($index -ge 0) { $resultbox.select($index, $searchtext.length) $resultbox.scrolltocaret() } else { $index = $resultbox.find($searchtext, 0, $resultbox.selectionstart , [system.windows.forms.richtextboxfinds]::none) } if($index -ge 0) { $resultbox.select($index, $searchtext.length) $resultbox.scrolltocaret() } else { $resultbox.selectionstart = 0 } }
here way it, goes through each character in richbox , checks color name. can rearrange needs
function searchbycolor { param ([string]$color) $result = ($i = 0; $i -lt $resultbox.textlength; $i++) { $resultbox.select($i, 1) if ($resultbox.selectioncolor.name -eq $color) { $resultbox.selectedtext } } $result -join '' }
to use it:
searchbycolor red
wiki
Comments
Post a Comment