|
|
Posted 08/09/2006 08:05:13 |
|
|
Forum Member
      
Group: Customers
Last Login: 26/03/2007 05:11:10
Posts: 46,
Visits: 152
|
|
| In my personal optimization crusade I found the function Truncate called many times and slow. Here is a way to fully remove the double for loop, multiple array, split and concatenation issue. Simple and working. Public Shared Function Truncate(ByVal Input As String, ByVal intMaxLen As Int32) As String If Input Is Nothing Then Return String.Empty End If If Input.Length <= intMaxLen Then ' no need to truncate Return Input End If ' search for last space before max lenght Dim iCutAt As Integer = Input.LastIndexOf(" "c, intMaxLen) Dim inputCut As String If iCutAt = -1 Then ' there is no space so cut anywhere inputCut = Input.Substring(0, intMaxLen) Else inputCut = Input.Substring(0, iCutAt) End If Return inputCut + "..." End Function I haven't done any benchmark but it's probably 100 times faster for both long and short input string.
Running InstantASP forum with many code change.
|
|
|
|