Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Performance enhancement of a vb.net function

Hi,

Is there a better way of writing this function for speed enhancement.I am using visual studio 2005.

Cheers
Public Function CleanSQL(ByVal SQL As String)
        If SQL = String.Empty Then
            Return String.Empty
            Exit Function
        End If
        SQL = SQL.Trim
        If SQL.StartsWith("'") Then Return String.Empty
        If SQL.StartsWith("--") Then Return String.Empty
        If SQL.EndsWith(";") Then SQL = SQL.Remove(SQL.Length - 1, 1)
        If SQL.ToUpper.EndsWith("GO") Then SQL = SQL.Remove(SQL.Length - 2, 2)
        SQL = SQL.Trim
        If SQL = vbNewLine Then Return String.Empty
        If SQL.StartsWith(Chr(13)) Then SQL = SQL.Substring(1)
        If SQL.StartsWith(vbNewLine) Then SQL = SQL.Substring(1)
        If SQL.StartsWith(Chr(8)) Then SQL = SQL.Substring(1)
        If SQL.StartsWith(Chr(9)) Then SQL = SQL.Substring(1)
        If SQL.StartsWith(Chr(10)) Then SQL = SQL.Substring(1)
        Return SQL.Trim
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Thanks CodeCruiser! It is slow compared to vb6.0.Just thinking are there faster string functions to subsitute:
StartsWith,EndsWith,SQL.Remove(SQL.Length - 1, 1)  
 etc.

Cheers
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers mate!!
Glad to help :-)