• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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

0
RIAS
Asked:
RIAS
  • 3
  • 2
2 Solutions
 
CodeCruiserCommented:
Is it slow? Why do you have to use this function?

You can combine lines such as these

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)

into


If SQL.StartsWith(Chr(13))  or SQL.StartsWith(vbNewLine) or SQL.StartsWith(Chr(8)) or SQL.StartsWith(Chr(9)) or SQL.StartsWith(Chr(10)) Then
  SQL = SQL.Substring(1)
End If
0
 
RIASAuthor Commented:
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
0
 
CodeCruiserCommented:
You can use Trim

If SQL.ToUpper.EndsWith("GO") Then SQL = SQL.Remove(SQL.Length - 2, 2)

to

If SQL.ToUpper.EndsWith("GO") Then SQL = SQL.Trim("GO")
0
 
RIASAuthor Commented:
Cheers mate!!
0
 
CodeCruiserCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now