fastest way to change case of string
- From: "RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx>
- Date: Wed, 24 May 2006 00:37:52 +0100
Looking for the very fastest way to change a string from
upper to lower case and vice versa.
Text enclosed in single quotes needs to stay as it is.
This is the best effort I have sofar:
Function ChangeCase(strString As String, bUpper As Boolean) As String
Dim i As Long
Dim bInQuotes As Boolean
Dim btArray() As Byte
'could do in one go if no single quotes, but it doesn't make it faster
'---------------------------------------------------------------------
btArray = strString
If bUpper Then
For i = 0 To UBound(btArray) Step 2
If btArray(i) = 39 Then
bInQuotes = (bInQuotes = False)
End If
If btArray(i) > 96 And btArray(i) < 123 Then
If bInQuotes = False Then
ChangeCase = ChangeCase & UCase(Mid$(strString, i \ 2 + 1, 1))
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Next
Else
For i = 0 To UBound(btArray) Step 2
If btArray(i) = 39 Then
bInQuotes = (bInQuotes = False)
End If
If btArray(i) > 64 And btArray(i) < 91 Then
If bInQuotes = False Then
ChangeCase = ChangeCase & LCase(Mid$(strString, i \ 2 + 1, 1))
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Else
ChangeCase = ChangeCase & Mid$(strString, i \ 2 + 1, 1)
End If
Next
End If
End Function
Any suggestions to make it faster?
RBS
.
- Follow-Ups:
- Re: 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: Larry Serflaten
- Re: fastest way to change case of string
- From: Larry Serflaten
- Re: fastest way to change case of string
- From: DanS
- Re: fastest way to change case of string
- From: Rick Rothstein
- Re: fastest way to change case of string
- Prev by Date: Re: Sending email in VB using only the Win32 API
- Next by Date: Re: fastest way to change case of string
- Previous by thread: PDF to Image
- Next by thread: Re: fastest way to change case of string
- Index(es):
Relevant Pages
|
Loading