Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace text in textbox. Yes that so simple...

Status
Not open for further replies.

Horowitz

Programmer
Jan 29, 2005
30
GR
Well, I write: textbox1.text.replace("hi","hello")
but nothing happens. I suppose that it will work like below:

Textbox1.text: After replacement:
hi hello
HI hello 'not case sensitive
high hellogh


Any "support" for this easy ...thing?

Tnx
 
textbox1.text is a function of tghe TextBox Class that returns a string.

Replace is a Function of the String class.

Try
textbox1.text = textbox1.text.replace("hi","hello")


Compare Code
 
The replace method does not act on the string it is invoked on but rather returns a new string base on the string it is invoked on as input.

So you need to do this:

textbox1.text = textbox1.text.replace("hi","hello")
 
Dim RegX
Dim SearchPattern, ReplacedText

Set RegX = NEW RegExp
SearchPattern = "hi"
RegX.Pattern = SearchPattern
RegX.Global = True
textbox1.text = RegX.Replace(textbox1.text, "hello")


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top