How do I split a variable in to two seperate variables?

Results 1 to 5 of 5

Thread: How do I split a variable in to two seperate variables?

  1. #1
    Ed Husar Guest

    Default How do I split a variable in to two seperate variables?

    I have a variable that is passed at my asp page. It contains a first name and last name like so, "Ed Husar". After it is passed I would like to break this into two seperate variables like so.<BR><BR>f_name = "Ed"<BR>l_name = "Husar"<BR><BR>Any help would be much appreciated.<BR><BR>Ed

  2. #2
    lincolntc Guest

    Default RE: How do I split a variable in to two seperate variables?

    Ed, use instr() on the receiving page to split the variable. You should search for the space and assign (character by character) the first half of the string to variable1. Then do the function again, this time removing the characters before the space and assigning the remainder to variable2. You will need the use of a temporary variable.

  3. #3
    ehusar01 Guest

    Default RE: How do I split a variable in to two seperate variables?

    If you can provide a good instr() resource please do. I am new to asp and can use any and all tips.<BR><BR>Thanks,<BR><BR>Ed

  4. #4
    Rob Holt Guest

    Default RE: How do I split a variable in to two seperate variables?

    Modifiy this code fragment: (it will only work if there is a space AFTER the first name, and should be OK if a name like Carlos Del Gato.)<BR><BR>&#060;%<BR>sFullName = Trim("Santa Claus")<BR>iFullNameLen = Len(sFullName)<BR>If iFullNameLen &#062; 1 Then<BR> iSpacePos = Instr(sFullName, chr(32))<BR> If iSpacePos &#062; 0 Then<BR> sFirst = Left(sFullName, iSpacePos - 1)<BR> sLast = Mid(iFullNameLen, iSpacePos + 1)<BR> End If<BR>End If<BR><BR>More error checking may be needed.<BR><BR>Lastly, go to your local used/half-proce book store, and get a few intro $5 books on ASP, VBScript, Javascript. This is Programming 101.<BR><BR>Rob


  5. #5
    ehusar01 Guest

    Default RE: How do I split a variable in to two seperate variables?

    Rob, thanks for the tip and the code. I have been meaning to buy an ASP book but have not found one I liked yet. If you can recommend one please do.<BR><BR>I modified your code and got it to work. Here is what I did,<BR><BR>&#060;%<BR>associate = request.form("getName")<BR><BR>sFullName = Trim(associate)<BR>iFullNameLen = Len(sFullName)<BR><BR>If iFullNameLen &#062; 1 Then<BR> iSpacePos = Instr(sFullName, chr(32))<BR> If iSpacePos &#062; 0 Then<BR> sFirst = Left(sFullName, iSpacePos - 1)<BR> sLast = Mid(sFullName, iSpacePos + 1)<BR> End If<BR>End If<BR><BR>response.write ("First Name:")<BR>response.write sFirst<BR>response.write ("<BR>")<BR>response.write ("Last Name:")<BR>response.write sLast<BR>response.write ("&#060;P&#062;")<BR>%&#062;<BR><BR>This is only part of the code but you get the idea. Thanks for your help.<BR><BR>Ed

Posting Permissions

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