firstname/lastname and string manipulation
Hello, I've got a very long list of names that comes from a column in an SQL table, and that column needs to be broken into a first name and a last name.. Because it is in a sense, a space-delimited field, I'm trying that route first. Not all of the names are in the standard format.. I'm using a dtml-in to loop through the returned records from an SQL query.. Within that loop, I'm using <dtml-var "_.string.split(SPEAKER,' ')[0]"> to successfully display the 'first name' (really the first part of the string) but when trying to use <dtml-var "_.string.split(SPEAKER,' ')[1]"> to display the part after the first space, even when I wrap that in a dtml-if I get an IndexError / list index out of range.. Does anyone have an obvious answer to what I'm doing wrong? Thank you, Chris
I havent tested this, (1) _.string.split returns a list (2) _.len(list) returns # of items in a list (3) Hence <dtml-if "_.len(_.string.split(SPEAKER, ' ')) > 1"> <dtml-var "_.string.split(SPEAKER,' ')[1]"> </dtml-if> David Chris Beaumont wrote:
Hello,
I've got a very long list of names that comes from a column in an SQL table, and that column needs to be broken into a first name and a last name.. Because it is in a sense, a space-delimited field, I'm trying that route first.
Not all of the names are in the standard format..
I'm using a dtml-in to loop through the returned records from an SQL query..
Within that loop, I'm using <dtml-var "_.string.split(SPEAKER,' ')[0]"> to successfully display the 'first name' (really the first part of the string) but when trying to use
<dtml-var "_.string.split(SPEAKER,' ')[1]">
to display the part after the first space, even when I wrap that in a dtml-if I get an IndexError / list index out of range..
Does anyone have an obvious answer to what I'm doing wrong?
Thank you, Chris
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
David, *Thank you* That did it! -Chris
I havent tested this, (1) _.string.split returns a list (2) _.len(list) returns # of items in a list (3) Hence <dtml-if "_.len(_.string.split(SPEAKER, ' ')) > 1"> <dtml-var "_.string.split(SPEAKER,' ')[1]"> </dtml-if>
David
Chris Beaumont wrote:
Hello,
I've got a very long list of names that comes from a column in an SQL table, and that column needs to be broken into a first name and a last name.. Because it is in a sense, a space-delimited field, I'm trying that route first.
Not all of the names are in the standard format..
I'm using a dtml-in to loop through the returned records from an SQL query..
Within that loop, I'm using <dtml-var "_.string.split(SPEAKER,' ')[0]"> to successfully display the 'first name' (really the first part of the string) but when trying to use
<dtml-var "_.string.split(SPEAKER,' ')[1]">
to display the part after the first space, even when I wrap that in a dtml-if I get an IndexError / list index out of range..
Does anyone have an obvious answer to what I'm doing wrong?
Thank you, Chris
participants (2)
-
Chris Beaumont -
David Hassalevris