Concatenating Strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lindiwemaduna
    New Member
    • Jul 2006
    • 4

    Concatenating Strings

    I want to concatenate values of two text boxes into one string but these should be separated by a space in the database table. i have tried all the following but twas not successful:

    Dim fullName as String
    Dim Surname as String

    Surname = String.Concat(t xtSurname.Text, Chr(173)) --this one is meant to append an empty string to txtSurname)

    FullName = String.Concat(S urname, txtName.Text) -- now I am concatenating tha above variable and txtName.Text, it failed.

    I have also tried this:
    I added 1 to the length of txtSurname, whatever length, to accomadate the space when I concatenate the values of the two textboxes i have already mentioned:

    Dim lenSurname as int16
    Dim FullName as String

    lenSurname = length(txtSurna me.Text) + 1

    Surname = txtSurname.Text .Padright(lenSu rname,"")

    FullName = String.Concat(S urname, txtName) - this one also does not work!

    I have also tried this one:

    FullName = txtSurname.Text & chr(173) & txtName.Text.

    Please help.
  • dotnet
    New Member
    • Jul 2006
    • 22

    #2
    Here is code for you

    Dim Name As String
    Dim Surname As String
    Dim FullName As String

    Name = "Nitin "
    Surname = " Mittal "
    If Surname.Length > 0 And Name.Length > 0 Then

    FullName = Name.Trim + " " + Surname.Trim
    Else
    FullName = Name.Trim
    End If

    You sould replace my variables by your variables

    Regards
    Nitin

    Comment

    • lindiwemaduna
      New Member
      • Jul 2006
      • 4

      #3
      Thank you Nitin, I have done exactly as you have advised but it still does not give the correct result. It does not leave the space in between the two variables.

      Regards
      Lindiwe

      Comment

      • dotnet
        New Member
        • Jul 2006
        • 22

        #4
        Well it should work.. i hav tested it on my machine..
        anyway.....can you provide your code so that I can debug it.

        Regards

        Comment

        • sasi_response
          New Member
          • Jul 2006
          • 3

          #5
          Use StringBuilder insted of String. You may get proper result.

          --Sasidhara K Karasi

          Comment

          Working...