-
Apr 29th, 2021, 12:15 PM
#1
Thread Starter
New Member
Using a menu item to clear everything, but text in a textbox
How would I make a menu item that clears everything in a textbox, but text? So like, just symbols (e.g. !"£$%^&*(/)? Basically a 'clean' button.
-
Apr 29th, 2021, 01:14 PM
#2
Re: Using a menu item to clear everything, but text in a textbox
-
Apr 29th, 2021, 07:14 PM
#3
Re: Using a menu item to clear everything, but text in a textbox
I would think that this would do the job:
vb.net Code:
myTextBox.Text = New String(myTextBox.Text.Where(Function(ch) Char.IsLetterOrDigit(ch)).ToArray())
A String is an IEnumerable(Of Char) and the Where method filters out every item in an enumerable list that doesn't satisfy the specified criteria. ToArray turns the filtered list into an array and a new String is created from that.
-
May 4th, 2021, 10:58 AM
#4
Thread Starter
New Member
Re: Using a menu item to clear everything, but text in a textbox
That works great, thank you so much!
-
May 4th, 2021, 07:49 PM
#5
Re: Using a menu item to clear everything, but text in a textbox
Don't forget to mark your thread Resolved using the Thread Tools menu if the issue has indeed been resolved.
-
May 13th, 2021, 01:44 PM
#6
Thread Starter
New Member
Re: Using a menu item to clear everything, but text in a textbox
Sorry, I've just been testing this and it seems that when 'cleaning' a list of text, it compacts all the text together?
-
May 13th, 2021, 04:33 PM
#7
Re: Using a menu item to clear everything, but text in a textbox
Code:
myTextBox.Text = New String(myTextBox.Text.Where(Function(ch) Char.IsLetterOrDigit(ch) OrElse ch = " "c OrElse ch = vbcr OrElse ch = vblf).ToArray())
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 13th, 2021, 07:49 PM
#8
Re: Using a menu item to clear everything, but text in a textbox
Originally Posted by JakeC
Sorry, I've just been testing this and it seems that when 'cleaning' a list of text, it compacts all the text together?
Perhaps you could provide a detailed description of the behaviour you expected and the behaviour you saw and how they differed. You could even provide an example or two. That way, we wouldn't have to guess, assume or interpret.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|