How to Concatenate two strings?

Results 1 to 3 of 3

Thread: How to Concatenate two strings?

  1. #1
    Join Date
    Dec 1969
    Posts
    74

    Default How to Concatenate two strings?

    I have two text boxes in the form and I need to put those two values into one Variable, so that I can add that to one field in the table in the database. How do I do this. Thanks for any info.

  2. #2
    Steve Cimino Guest

    Default + or &

    firststring + secondstring = concatenatedstring<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    96,118

    Default NEVER use + for concatenation

    Reason:<BR><BR>VBS uses the types of the variables to decide whether the + means mathematical addition or string concatenation.<BR><BR>So if you *THINK* you have a pair of strings (or one string and one number or or or) but in fact you have a pair of numeric values (including dates and currencies and times and objects whose default value happens to be numeric) and you use +, then you will end up with a number by doing addition.<BR><BR>If you want to be SURE you are doing string concatenation, use the & instead. The only other meaning of & in VBScript is to introduce non-decimal constants (as in the hex values &h00FE, &hA000, etc.) and it won&#039t be confused with that unless you have a pretty weird variable name (and even then a space after the & solves the problem).<BR><BR>The most insidious errors can creep in when you use + with objects, especially, as you can indeed end up doing addition when you did not expect it.<BR><BR>Note that in JavaScript you have no choice: You must use + for both purposes. So in JS, pay special attention to the data types with which you are using that operator.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •