How do I parse a string every 2nd comma?

Results 1 to 4 of 4

Thread: How do I parse a string every 2nd comma?

  1. #1
    Join Date
    Dec 1969

    Default How do I parse a string every 2nd comma?

    I need to parse a text string every second comma. Here&#039;s why...<BR><BR>The form submits several names all saved under one form field. The output looks like this:<BR><BR>Smith, John, Burke, Bill, Piper, Peter<BR><BR>Where their names are:<BR><BR>Smith, John<BR>Burke, Bill<BR>Piper, Peter<BR><BR>How do I parse the string so it separates each name set (Smith, John being a name set) and put the names in an array so I can save the names to a database?

  2. #2
    Join Date
    Dec 1969

    Default RE: How do I parse a string every 2nd comma?

    Use Split, then concatenate every other element... you&#039;ll have to do this manually.<BR><BR>

  3. #3
    keith5000 Guest

    Default use Split and then...

    use the Split function:<BR>names_split = split(names, ",")<BR><BR>what you get is a zero-based array where<BR>element 0 = "Smith"<BR>element 1 = "John"<BR>element 2 = "Burke"<BR>etc.<BR><BR>with a loop you can piece together the pairs.<BR><BR><BR>side note: if you&#039;re saving the names to the database, why aren&#039;t you storing first and last names separate?

  4. #4
    Join Date
    Dec 1969

    Default A BETTER WAY!!!

    They are *ALREADY* in an ARRAY! Well, an array of sorts:<BR><BR>&#060;%<BR>For nn = 1 To Request.Form("theNames").Count<BR>&nbsp; &nbsp; currentName = Request.Form("theNames")(nn)<BR>&nbsp; &nbsp; ... so add this name to the DB ...<BR>Next<BR>%&#062;<BR><BR>The comma-delimited list format only happens when you get the "raw" data from a multi-element name. By treating it as an array (as above), there isn&#039;t any confusion of which comma means what.<BR><BR>Incidentally, *this* code works even if some user doesn&#039;t HAVE two names (and thus no comma).<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