Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
A program that removes all occurrences of a string...
Author:
Theodore W. Barkhuizen
E-mail:
Click to e-mail author
Submitted:
4/1/2002
Version:
VB6
Compatibility:
VB6
Category:
String Manipulation
Views:
11293
A program that removes all occurrences of a string from another string without using the built in function 'replace'.
Declarations:
Option Explicit Option Compare Text 'This program takes a string and then removes all occurrences of the 'string "Remove" in the string 'The search for the sub string is case insensitive, rather than converting the 'strings into lower case or uppercase with function UCase/Lcase, use option 'compare text to do a case insensitive search
Code:
Private Sub cmdRemove_String_Click() Dim leftString As String Dim rightString As String Dim intCount As Integer Dim intPosition As Integer Dim removeCount As Integer removeCount = Len(txtRemove) For intCount = 1 To Len(txtInput) intPosition = InStr(intCount, txtInput, txtRemove) If intPosition <> 0 Then leftString = Left$(txtInput, intPosition - 1) rightString = Mid$(txtInput, intPosition + Len(txtRemove), Len(txtInput) - intPosition) txtInput = leftString & rightString End If If intPosition = 0 Then removeCount = removeCount - 1 If removeCount = 0 Then lblDisplay = "All characters were removed or none were found" Exit Sub End If txtRemove = Mid$(txtRemove, removeCount, removeCount) End If Next intCount End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement