Wednesday, March 09, 2005

String Operations

I found this on microsoft's website. I didn't know that I can use MID function on the LHS and converting string to ASCII will speed up the process. Cool!!

"The following points provide suggestions for ways to enhance the performance of string operations:
Minimize concatenation operations when you can. You can use the Mid function on the left side of the equal sign to replace characters within the string, rather than concatenating them together. The drawback to using the Mid function is that the replacement string must be the same length as the substring you are replacing.

Dim strText As String

strText = 'this is a test'
Mid(strText, 11, 4) = 'tent'
Debug.Print strText

Microsoft Visual Basic for Applications (VBA) provides a number of intrinsic string constants that you can use to replace function calls. For example, you can use the vbCrLf constant to represent a carriage return/linefeed combination within a string, rather than using Chr(13) & Chr(10).
String-comparison operations are slow. Sometimes, you can avoid them by converting a character in the string to an ANSI value. For example, the following code checks whether the first character in a string is a space:
If Asc(strText) = 32 Then

The previous code is faster than the following:
If Left(strText, 1) = ' ' Then"

Labels:


Comments: Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?