Difference between Trim and Trim$ Function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NithyaMM
    New Member
    • Jan 2008
    • 5

    Difference between Trim and Trim$ Function?

    am new to VB, can anyone help me









    Nithya M M
  • NithyaMM
    New Member
    • Jan 2008
    • 5

    #2
    Difference between Trim and Trim$ Function?

    Hi,
    am new to VB, anyone help me
    it s very useful to me
    urgent plz

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Normal functions are variant functions
      and the .....$ functions are optimized for string operations only, so executes faster.

      Please find a related discussion here.

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        Originally posted by NithyaMM
        am new to VB, can anyone help me

        Nithya M M
        It depends on the version of VB your'e using, but i think the main difference is that trim returns a variant and trim$ returns a string and that many say one is faster than the other... i'll make some tests later.

        Anyway, i'll keep subscribed here to check other answers.

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by kadghar
          ... i'll make some tests later.
          (...)
          Im soo curious... i couldnt wait much time =P

          yes, Trim$ is faster, try:

          [CODE=vb]Sub HelloTest()
          Dim str1 As String
          Dim str2 As String
          Dim t As Single
          Dim t2 As Single
          Dim i As Long
          str1 = " hello "
          t = Timer
          For i = 1 To 10000000
          str2 = Trim(str1)
          Next
          t2 = Timer - t
          t = Timer
          For i = 1 To 10000000
          str2 = Trim$(str1)
          Next
          MsgBox "Trim: " & t2 & " seconds." & Chr(13) & "Trim$: " & Timer - t & " seconds."
          End Sub[/CODE]

          Comment

          • NithyaMM
            New Member
            • Jan 2008
            • 5

            #6
            Originally posted by kadghar
            It depends on the version of VB your'e using, but i think the main difference is that trim returns a variant and trim$ returns a string and that many say one is faster than the other... i'll make some tests later.

            Anyway, i'll keep subscribed here to check other answers.


            Thanks 4 reply

            Regards
            Nithya MM

            Comment

            • NithyaMM
              New Member
              • Jan 2008
              • 5

              #7
              Thanks 4 reply


              Regards
              NithyaMM

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                Please do not start duplicate threads.

                Both the threads are merged for better management of the forum.

                Comment

                Working...