|
-
Dec 12th, 2003, 05:17 PM
#1
Thread Starter
Member
find, replace, words in textbox
Hello, I am new to vb.net. This is my second small final exam project for class. I have to have a text box with some text in it. Then I have put a word in a field such as box and then in anothe field I have to enter another word such as rocks. What I then have to do is hit a button that will search the text in the textbox for the word box and replace it with the word rocks for example. Any one have any ideas. I am pretty inexperienced at programming.
Im supposed to be working with strings, and substring i guess.
-
Dec 12th, 2003, 07:00 PM
#2
Frenzied Member
VB Code:
Dim s as String=Textbox1.Text
Textbox1.Text=s.Replace("Box", "Rocks")
Remember that this function is case sensitive, so 'Box' is different from 'box'.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Dec 12th, 2003, 08:46 PM
#3
Thread Starter
Member
?
what exactly does this function do? If you dont mind me asking
-
Dec 12th, 2003, 08:55 PM
#4
Frenzied Member
Replace method of string searches the string for a character or string and replace it with another character or string and returns a new string.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Dec 12th, 2003, 10:50 PM
#5
Thread Starter
Member
text fields
will this work with one large textbox with some text typed into it. then have two smaller textboxes one where i can enter the word I want to find and one where I enter the one that I want to replace it with. Then after putting the two words in I want to hit a button that will go through search the text and then replace it with the word from the replace field.
-
Dec 12th, 2003, 11:31 PM
#6
Frenzied Member
Yes. Imagine you have three textboxes (txtMain, txtFind, txtReplace) and a button. Then in the click event of the button:
VB Code:
Dim s as String = txtMain.Text
txtMain.Text = s.Replace(txtFind.Text, txtReplace.Text)
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Dec 12th, 2003, 11:37 PM
#7
Frenzied Member
Lunatic3, it's nice of you to help out a newbie (god knows we all need help). But jeez, a student?
The mind is not a vessel to be filled, but a fire to be ignited.
doro40282, if you've gone to class, you might have learned how to press F1. Sorry, that was rude. My point is that there is no reason to ask what a method does when the answer is a click away.
Real programmers never ask "will this work", give it a try first. If it doesn't work, post what you've tried so far.
-
Dec 13th, 2003, 12:36 AM
#8
Thread Starter
Member
student
yes i am a student and not a real programmer yet. I am learning as I go. One thing that helps is looking at other code and breaking it down to understand how that works. I have been doing alot of programming these past few weeks and I greatly appreciate the help you guys are giving me I am learning alot from these forums. I am trying to teach myself my first language and I didnt miss one class all semester by the way
-
Dec 13th, 2003, 12:39 AM
#9
Thread Starter
Member
method
and I did read up on that method, i also came across a wildcard method. but the only thing is I try reading it and there is alot that I still do not understand. Some of the information is pretty deep.
-
Dec 13th, 2003, 02:46 PM
#10
Frenzied Member
Are you still having troubles accomplishing your task?
-
Dec 13th, 2003, 03:07 PM
#11
Thread Starter
Member
find search replace
yes I am having problems. Im really not sure how to start this. I read up on a couple methods like the wildcard method and string replace but Im really not sure how to implement them. I know that when the text is typed into the textbox I need to convert it to a string. And then search the string however many characters the word is that I want to find which could be s.length maybee. and then I am confused about how to replace it maybee using a substring (x, ) or something like that. I have a general understanding of it in english but I have trouble putting it into code.
-
Dec 13th, 2003, 03:21 PM
#12
Frenzied Member
Using Lunatic3's method, I put three text boxes and a button on a form. Type word to search for in TextBox1, the replace string in TextBox2, and a bunch of text to search in TextBox3. Then when you click the button,
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox3.Text = TextBox3.Text.Replace(TextBox1.Text, TextBox2.Text)
End Sub
-
Dec 14th, 2003, 06:12 PM
#13
Thread Starter
Member
worked
thank you that worked well I really appreiciate it. I am also trying to get it to work another way. I'll see if I can get it to work both ways. thanks again
-
Dec 18th, 2003, 09:38 AM
#14
Thread Starter
Member
Regex
Does anyone know where I can find some information about using regular expressions to manipulate strings?
-
Dec 20th, 2003, 10:54 PM
#15
Frenzied Member
If you really want to learn it, download chapter 9 of the book in the following link: http://www.oreilly.com/catalog/regex...ter/index.html
but it may be a little bit hard to start with.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
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
|