ok i have 2 textbox's and 1 button i have 1 big textbox that has a buch of number's in it and the number i want to delete is in the top textbox how can i delete number 2 ? from the big textbox ?
http://img23.imageshack.us/img23/8021/39211582.png
Printable View
ok i have 2 textbox's and 1 button i have 1 big textbox that has a buch of number's in it and the number i want to delete is in the top textbox how can i delete number 2 ? from the big textbox ?
http://img23.imageshack.us/img23/8021/39211582.png
You can use IndexOf to find the location of the desired text in the TextBox. You can then set the SelectionStart and SelectionLength properties to select that text. You can then set the SelectedText property to replace the currently selected text. To remove it you would replace it with an empty string or Nothing.
k i dident under stand what you just said can you just post the code cause im a noobie
All you have to do is call methods and set properties and you already know how to do that because you've already done it. Get the Text property of the TextBox to get a String. Call the IndexOf method of that String to get the location of the desired substring. Set the SelectionStart property of the TextBox to set the caret position. Set the SelectionLength property of the TextBox to select the desired text. Set the SelectedText property to replace the selected text. It's just a series of steps and each one is very simple. Try to implement them one by one and if you get stuck on one then post back with what you've done so far.
Alternatively, you can just wait for someone to do it for you but, believe me, you'll learn more by trying things for yourself first.
You're never going to stop being a noobie if you expect people to just post code for you.
If you just want to delete the first instance of the word, then it is pretty straightforward. We are going to search the Text of the big TextBox for the IndexOf the first occurence of the Text in your search TextBox. Then we are going to Remove the correct number of characters from the big TextBox, starting from the IndexOf the first occurence.
This is the long-winded version, which should give you an understanding of what is going on. The short version would be:Code:Dim strToEdit, strSearch, strEditedText As String
Dim intFirstIndex, intLength As Integer
strToEdit = bigTextBox.Text
strSearch = smallTextBox.Text
intFirstIndex = strToEdit.IndexOf(strSearch)
intLength = strSearch.Length
strEditedText = strToEdit.Remove(intFirstIndex, intLength)
bigTextBox.Text = strEditedText
Code:bigTextBox.Text = _
bigTextBox.Text.Remove( _
bigTextBox.Text.IndexOf( _
smallTextBox.Text _
), _
smallTextBox.Text.Length _
)
MaximilianMayrhofer & jmcilhinney thank you thank you it works :) but how do i fix it so it doesn't do this
ALT
ARE
ART
ATE
EAR
EAT
ERA
ETA
HAE
HAM
HEM
HER
LAM
LAT
LEA
MAE
MAR
MAT
MEL
RAH
RAM
REM
RET
TAM
TAR
TEL
THE
ALME
EARL
EATH
HAET
how can i remove the
?
i need it like this
TAM
TAR
TEL
THE
ALME
EARL
EATH
HAET
etc thanks
think about what you are asking? you can probably fix it by adding
& Environment.Newline
to one of the statements you were given.
like this ?
casue that doesn't work ?Code:bigTextBox.Text = _
bigTextBox.Text.Remove( _
bigTextBox.Text.IndexOf( _
smallTextBox.Text _
), _
smallTextBox.Text.Length & Environment.NewLine)
anyone know the answer ?
max gave you 8 lines. if it doesn't work on one, try another.
FYI - pm'ing someone with code questions, unless they have stated to do so, is frowned upon.
one other thing, this and some of the other problems you have posted might have been done better (easier?) with a listbox.
Tweaker, try:
You can set yourCharacter to whatever you want and then the code Replace will find it (along with the line below it) and replace it with "", in otherwords nothing, so it will delete it.Code:Dim yourCharacter as string
bigTextBox.Text = bigTextBox.Text.Replace(yourCharacter & ControlChars.NewLine, "")
Also, dbasnett has a point with using listboxes. What exactly are you trying to do with this list of numbers?
That method will work if you want to get rid of every occurence of the search string. The example I gave was to specifically get rid of the first occurence. Now the OP can choose what he's actually looking for :)
Other than that, I would suggest using Environment.NewLine rather than ControlChars.NewLine.
I'm also going to throw my two cents in there and ask why the OP isn't using a ListBox.