By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

Difference between Trim and Trim$ Function?

P: 5
am new to VB, can anyone help me









Nithya M M
Jan 18 '08 #1
Share this Question
Share on Google+
7 Replies


P: 5
Hi,
am new to VB, anyone help me
it s very useful to me
urgent plz
Jan 18 '08 #2

debasisdas
Expert 5K+
P: 8,127
Normal functions are variant functions
and the .....$ functions are optimized for string operations only, so executes faster.

Please find a related discussion here.
Jan 18 '08 #3

kadghar
Expert 100+
P: 1,295
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.
Jan 18 '08 #4

kadghar
Expert 100+
P: 1,295
... i'll make some tests later.
(...)
Im soo curious... i couldnt wait much time =P

yes, Trim$ is faster, try:

Expand|Select|Wrap|Line Numbers
  1. Sub HelloTest()
  2. Dim str1 As String
  3. Dim str2 As String
  4. Dim t As Single
  5. Dim t2 As Single
  6. Dim i As Long
  7. str1 = "    hello    "
  8. t = Timer
  9. For i = 1 To 10000000
  10.     str2 = Trim(str1)
  11. Next
  12. t2 = Timer - t
  13. t = Timer
  14. For i = 1 To 10000000
  15.     str2 = Trim$(str1)
  16. Next
  17. MsgBox "Trim: " & t2 & " seconds." & Chr(13) & "Trim$: " & Timer - t & " seconds."
  18. End Sub
Jan 18 '08 #5

P: 5
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
Jan 21 '08 #6

P: 5
Thanks 4 reply


Regards
NithyaMM
Jan 21 '08 #7

debasisdas
Expert 5K+
P: 8,127
Please do not start duplicate threads.

Both the threads are merged for better management of the forum.
Jan 21 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.