|
Visual Basic (VB6 and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Visual Basic Library
This page was last updated on Saturday, November 24, 2001
Public Function strOnly(strIn As String, strRef As String) As String ' Procedure : strOnly ' Description: This code returns only those characters in strIn which can be found in strRef. ' Copyright: Chris Greaves Inc. ' Inputs: A data string, a reference string. ' Returns: STRING. ' Assumes: Nothing ' Side Effects: None. ' Tested: By the calls shown below. ' Posted Woody 2002/02/15 Dim strOut As String strOut = "" Dim lngI As Long For lngI = 1 To Len(strIn) Dim strMid As String strMid = Mid(strIn, lngI, 1) If InStr(1, strRef, strMid) > 0 Then strOut = strOut & strMid Else End If Next lngI strOnly = strOut 'Sub TESTstrOnly() 'MsgBox strOnly("alphabet", "abcde") ' regular use "aabe" of 1st string exist in 2nd string 'MsgBox Len(strOnly("", "abcde")) ' empty source string yields empty result string, length = 0 'MsgBox Len(strOnly("alphabet", "")) ' empty reference string yields empty result string, length = 0 'MsgBox strOnly("alphabetand1digit", "abcdefghijklmnopqrstuvwxyz") ' strip digit "1" 'End Sub End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Monday, November 19, 2001 |