Mikey
Mikey

Reputation: 133

Filtering a Multiline Textbox

I was trying to fiter out a series of names from one textbox and copy filtered list to another textbox. The problem I'm having is that when I use my add_click button it is only working under a few conditions. When I have the names that I want to filter in the list(front or end of list) no results added to the destination textbox. Also it just blanks out the destination box if I'm adding a item that should be filtered-out(assuming adding by accident to a good list of names, so even good names blanked out). So if I have 5 items that will copy over and one item that should be filtered out the whole destination box is blanked out. When I remove the filtered-out items from the textbox list then the destination box is filled with those names. These are the prefixes below I'm filtering out.

$objOutputBox.Text = $logOutputBox.text |?{$_ -notmatch "etc$|^mint|kssc*|mmm|charl"}

Any idea's how I can arrange this so it will filter out the unwanted machines and add the desired machines? Right now it only works if every name I add does not have the filtered out pre-fix or post-fix. My reasoning is trying to get it to work eitherway and the filter-out names will be removed while adding desired names at the click of a button. Any help is appreciated.

Upvotes: 0

Views: 738

Answers (1)

Frode F.
Frode F.

Reputation: 54891

I'm not sure I understand this properly. It's a lot of text and not much samples. You should consider that now and for future references. A "picture"(sample) is worth a thousand words. :-) Are the names you want to filter split by linebreaks, space, a character? I couldn't seem to find that in your text.

To get you started, the Text property is a single string-object with linebreaks. Where-object (?) works by matching the current object to the rules. Now, since Text is a single string-object, it will either go through(it passed your test), or none of it will be come through. To fix this, you could try splitting up the string in an array depending on how you split the names in the textbox. Btw, when you use regex for matching, you should use single quotes, not double quotes because of special characters.

#Sample with list seperated by linebreaks
PS > $listseperatedbylinebreaks = @"
this
is
my
charl
list
"@

PS > $listseperatedbylinebreaks.Split("`n") | ? { $_ -notmatch "etc$|^mint|kssc*|mmm|charl"}

this
is
my
list

#Sample with list seperated by linebreaks and spaces    
PS > $listseperatedbylinebreaksandspaces = @"
this is
my list sdsadetc
"@

PS > $listseperatedbylinebreaksandspaces.Split("`n ", [System.StringSplitOptions]::RemoveEmptyEntries) | ? { $_ -notmatch "etc$|^mint|kssc*|mmm|charl"}

this
is
my
list

I hope this gave you an idea of how to solve it. If not, please provide some more samples(ex. input-textbox content), so I can understand it better.

Upvotes: 1

Related Questions