|
Visual Basic (VB 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! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function strSqueezeConsecutive(strIn As String, iCount As Integer) As String
' Procedure : strSqueezeConsecutive
' Description: Return the supplied string with not more than iCount consecutive repetions of any character.
' Copyright: Chris Greaves Inc.
' Inputs: STRING, Integer
' Returns: STRING
' Assumes: Nothing
' Side Effects: None.
' Tested: By the calls shown below.
If iCount >= Len(strIn) Then
strSqueezeConsecutive = strIn
Else
Dim strResult As String
strResult = ""
Dim iSame As Integer
iSame = 1
Dim strChPrevious As String
strChPrevious = ""
Dim ich As Integer
For ich = 1 To Len(strIn)
If strChPrevious = Mid$(strIn, ich, 1) Then
iSame = iSame + 1
If iSame > iCount Then
Else
strResult = strResult & Mid$(strIn, ich, 1)
End If
Else
strChPrevious = Mid$(strIn, ich, 1)
iSame = 1
strResult = strResult & Mid$(strIn, ich, 1)
End If
Next ich
strSqueezeConsecutive = strResult
End If
'Sub TESTstrSqueezeConsecutive()
'MsgBox strSqueezeConsecutive("abbcccddddded", 3) ' abbcccddded
'MsgBox strSqueezeConsecutive("abbcccddddded", 2) ' abbccdded
'MsgBox strSqueezeConsecutive("abbcccddddded", 1) ' abcded
'MsgBox strSqueezeConsecutive("abbcccddddded", 0) ' abcded
'MsgBox strSqueezeConsecutive("abbcccddddded", 23) ' abbcccddddded
'MsgBox strSqueezeConsecutive("", 3) ' ""
'MsgBox strSqueezeConsecutive("abcded", -2) ' abbccdded
'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 Thursday, November 15, 2001 |