Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String functions in VB
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00758442
Message ID:
00758922
Views:
21
This message has been marked as a message which has helped to the initial question of the thread.
>>1. You can use "+" for strings - I think there's no differences between "+" and "&" for strings. But code with "&" is more readable - when you saw it, you know that this expression returns string.

Actually, there are some slight differences in the usage, one of them having to do with NULLs, the other having to do with VB's implicit data type conversions.

If you use "&" to concatenate a value with a null value, you get the value:
"Vin" & null = "vin". If you use the plus sign, you get Null. This can really burn you if you are concatenating fields from an ADO recordset, let's say.

In addition, VB tries to be smart enought to implicitly convert data. So, if one of your fields is not a string, you will see differences in the return values of "+" and "&." As a result:
2 & 2 ' returns '22'
2 + 2 ' returns 4
"2" & 2 ' returns '22'
"2" + 2 ' returns 4
"2" & "2" ' returns '22'
"2" + "2" ' returns '22'




>>2. I never see official documentation how effective is some VB/VBScript function. So you can do your own tests with many CStr's and, for example, Str$'s and see what is the difference.

The $ versions of commands are a touch quicker, and preferable unless you have a reason not to use them. But, generally, VB string concatenation speed is very slow especially when concatenating strings. If possible, and where possible, use byte arrays or fixed-length strings to increase performance....


>>3. About Trim() - I prefer safety to speed. If you hard test some function (IN ALL POSSIBLE SITUATIONS) and it never insert spaces, omit Trim(). But often I have no time to these tests...
The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts. - Bertrand Russell
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform