Re: fastest way to change case of string
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Wed, 24 May 2006 10:06:51 -0500
"RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx> wrote
Have tested this now and changing the case in the supplied
string rather than concatenating a new string is indeed much faster.
This also means that as there usually are not that many quotes it is worth
it to see
where the quotes are and run UCase or LCase on larger strings. Haven't done
this yet,
but I suspect that will make it much faster still.
You tend to write large routines, I strive to only do what is required.
I suspect (and this has been discussed before) that copying the text
into and out of the byte array will take a significant amount of time
when compared to the actual work being done. You can avoid that
by simply working with the text data. Check out the addition I added
to allow for different case selections... ;-)
HTH
LFS
(In a new form...)
Option Explicit
Private Enum ChangeCaseOption
ccUpperCase = 1
ccLowerCase = 2
ccProperCase = 3
End Enum
Private Sub Form_Load()
Const TestData = "ABcd 'EFgh' IJkl 'MNop' QRst"
Debug.Print ChangeCaseX(TestData, ccUpperCase)
Debug.Print ChangeCaseX(TestData, ccLowerCase)
Debug.Print ChangeCaseX(TestData, ccProperCase)
End Sub
Private Function ChangeCaseX(ByRef Text As String, ByVal Action As ChangeCaseOption) As String
Dim quoted As Collection
Dim posA As Long, posB As Long, vlu
Const QUOTE = "'"
' Change case
ChangeCaseX = StrConv(Text, Action)
posA = InStr(1, Text, QUOTE, vbBinaryCompare)
If posA > 0 Then
' Find quotes
Set quoted = New Collection
Do While posA > 0
posB = InStr(posA + 1, Text, QUOTE, vbBinaryCompare)
quoted.Add Array(posA + 1, posB - posA - 1)
posA = InStr(posB + 1, Text, QUOTE, vbBinaryCompare)
Loop
' Restore quoted text
For Each vlu In quoted
Mid(ChangeCaseX, vlu(0), vlu(1)) = Mid$(Text, vlu(0), vlu(1))
Next
End If
End Function
.
- Follow-Ups:
- Re: fastest way to change case of string
- From: Rick Rothstein
- Re: fastest way to change case of string
- References:
- fastest way to change case of string
- From: RB Smissaert
- Re: fastest way to change case of string
- From: RB Smissaert
- Re: fastest way to change case of string
- From: RB Smissaert
- fastest way to change case of string
- Prev by Date: Re: Plz tell me the code to transfer data from database table into text file.
- Next by Date: Re: Error Running Code From Q194789 (List Bins)
- Previous by thread: Re: fastest way to change case of string
- Next by thread: Re: fastest way to change case of string
- Index(es):
Relevant Pages
|
Loading