Skip to main content
Inspiring
February 15, 2007
Question

string handling - splitting a variable

  • February 15, 2007
  • 5 replies
  • 704 views
Hi,

i have a name variable that is a persons full name eg. "John Doe".

What string handling function can I use to split the name into two variables eg fname="John" lname="Doe"?

i think it might be something to do with locating the " "(space) character but I don't know how to actually do it.

Thanks
    This topic has been closed for replies.

    5 replies

    February 15, 2007
    lol @ 'van der Longname' :)
    Inspiring
    February 15, 2007
    Sabaidee wrote:
    > or name like John I. Doe, Jr. ???

    you can go a long way by simply testing the listLen & handling as many special
    cases as you can. but no, this isn't a trivial task, more so depending on the
    locale.

    BKBK
    Community Expert
    Community Expert
    February 15, 2007
    this isn't a trivial task, more so depending on the locale.
    Indeed. In the Netherlands, Ian's example comprises just 2 names -- first name: Joe, last name: van der Longname.

    Inspiring
    February 15, 2007
    or name like John I. Doe, Jr. ???
    Inspiring
    February 15, 2007
    you are on the right track! look up list functions in cf reference or online (i.e. listfirst, listlast, listgetat,...)
    Inspiring
    February 15, 2007
    <cfset fullname="Ian Skinner">
    <cfset fName = listFirst(fullName," ")>
    <cfset lName = listLast(fullName," ")>

    But what do plan to do with a name like "Joe Van Der LongName"?