[AccessD] Use Regex - Create Camel Case

jwcolby jwcolby at colbyconsulting.com
Wed Oct 3 06:43:40 CDT 2007


Shamil,

And while I haven't spoken up yet (nor had time to try all this) I am
watching the thread closely.

John W. Colby
Colby Consulting
www.ColbyConsulting.com 
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: Monday, October 01, 2007 7:29 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Use Regex - Create Camel Case

<<<
Indeed for long strings (some 10K) this is so slow that it is hard to
believe.
>>>
Hi Gustav,

Yes, I'm aware of that.

<<<
As we all know, for validation of a user input in a textbox, speed is of
zero practical importance
>>>
Yes, that's clear but:

1) this thread was originated with the request of JC to find the quickest
way to "jam"/CamelCase strings...

2) the original request was about RegEx and VB.NET/C#. The hypothesis was
that RegEx could deliver the quickest solution. This hypothesis isn't yet
proved in this thread...

3) saving even one CPU cycle while programming user input could result in a
lot of saved energy if we count how many computers are currently running all
around the world :) - a kind of kidding you know: of course spending hours
trying to save a second for an algorithm, which validates user input could
be even more waste of energy - but for JC's task saving a sec could result
in significant time gains because of specifics of the business processes of
his customer requesting to "crunch" zillion gigabytes of data...

--
Shamil
 
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Monday, October 01, 2007 12:57 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Use Regex - Create Camel Case

Hi Max and Shamil

Max, the main reason for VBA running slow on string concatenation is this
construct:

        strResult = strResult & strBit

Indeed for long strings (some 10K) this is so slow that it is hard to
believe.
The traditional work-around is to create a dummy target string and then
replace the chars one by one using Mid().
Here's an example (though path/file names seldom are so long that it
matters):

Public Function TrimFileName( _
  ByVal strFileName As String) _
  As String

' Replaces characters in strFileName that are ' not allowed by Windows as a
file name.
' Truncates length of strFileName to clngFileNameLen.
'
' 2000-12-07. Gustav Brock, Cactus Data ApS, Copenhagen ' 2002-05-22.
Replaced string concatenating with Mid().

  ' No special error handling.
  On Error Resume Next

  ' String containing all not allowed characters.
  Const cstrInValidChars  As String = "\/:*?""<>|"
  ' Replace character for not allowed characters.
  Const cstrReplaceChar   As String * 1 = "-"
  ' Maximum length of a file name.
  Const clngFileNameLen  As Long = 255
  
  Dim lngLen    As Long
  Dim lngPos    As Long
  Dim strChar   As String
  Dim strTrim   As String
  
  ' Strip leading and trailing spaces.
  strTrim = Left(Trim(strFileName), clngFileNameLen)
  lngLen = Len(strTrim)
  For lngPos = 1 To lngLen Step 1
    strChar = Mid(strTrim, lngPos, 1)
    If InStr(cstrInValidChars, strChar) > 0 Then
      Mid(strTrim, lngPos) = cstrReplaceChar
    End If
  Next
    
  TrimFileName = strTrim

End Function

Shamil, I have not been working with this in C# but I think you are on the
right track using arrays. I hope to find some time to experiment with your
code examples. 
As we all know, for validation of a user input in a textbox, speed is of
zero practical importance, but from time to time your task is to manipulate
not one but thousands of strings and then it matters.

/gustav


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list