|
|
|
|
![]() ![]() |
May 12 2005, 08:41 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 19 Joined: 12-May 05 Member No.: 5,018 |
This tutorial will go over how to effectively use the Replace function in Visual Basic.
1. So you have a string. Whether it be a label caption, an entry in a text box by the user of your program, or an item in a combo box. Let's say this is a bad string, something you do not want to appear. For instance, a user types "X is gay" in a text box, and you want to change that to something else. You can simply have it be deleted, or replaced with another value. 2. To make this work when a user types something in a textbox, you will need to use this sub: CODE Private Sub Text1_Change() End Sub Then we'll use the replace function. This looks like: CODE Replace(Expression, WhatToReplace, ReplaceWithWhat) 3. Now we want to find the text "X is gay" in the textbox. Remember our Text1_Change() Sub? We'll now insert the following code inside that sub. CODE Private Sub Text1_Change() Dim txt txt = Text1.Text If InStr(1, Text1.Text, "X is gay") > 0 Then Text1.Text = Replace(txt, "X is gay", "User is gay") End If End Sub 4. Done! What this code does is look for the value "X is gay" in Text1.Text, and if that is greater than 0 (meaning true) it replaces text in Text1.Text with "User is gay" That's all there is to it. If you have any questions, feel free to e-mail me at ViRuaL@gmail.com. If you thought this was completely useless, feel free to flame it into oblivion. |
|
|
|
May 12 2005, 09:02 PM
Post
#2
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 |
Good job
All the best, m^e |
|
|
|
May 12 2005, 09:05 PM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 19 Joined: 12-May 05 Member No.: 5,018 |
Why thank you.
I will be posting a lot of cool things I've learned... Looking forward to my free hosting |
|
|
|
Sep 27 2007, 07:38 AM
Post
#4
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
I've been trying to figure this out for a while and this seems almost there... but when I add another "Remove" line only the top one works... any ideas?
|
|
|
|
Mar 30 2008, 09:54 PM
Post
#5
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
VB replacing strings...
Visual Basic: Replace Explained! How to relplace an oldword with an new word??? -question by Sukanya |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 03:42 AM |