LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  String Concatenation with a list

    Employee
    Posted 09-22-2015 23:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: arkore

    I have a need to concatenate a list of strings with single characters. I've figured out how to do it but it seems quite ugly. I would welcome any advice on a method I'm missing.

    I have a list of strings named "inputs"

    To concatenate a single character "<" to the start of every string in the list I first need to create a list of this character with a dynamic length as so:

    lth = "".pad(len(inputs),"<").replace("<","<,").left(2*l en(inputs)-1)

    Then I can use map to join the two lists of strings elementwise:

    joined = map(&strcat,lth,inputs)

    Is there a better way of achieving the same result?


  • 2.  RE: String Concatenation with a list

    Employee
    Posted 09-23-2015 14:28

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    I think the approach you've laid out is pretty solid. It is slightly confusing because 'lth' is really a string that you'll be splitting by a comma to get a list back out. I probably would've used a while loop to go through each item in the list and then adding the "<" on, but I'm not sure that'd be cleaner.

    You say you have a list of strings. I assume it was initially a comma-separated string? And after you add the "<" to each itme, what do yo plan on doing with the resulting list?


  • 3.  RE: String Concatenation with a list

    Employee
    Posted 09-24-2015 20:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: arkore

    I'm building an extension to the existing XML writing node from LAL so that it is able to handle nested XML tables and associated XML tag attributes. I need to do this to conform to the GML v3 specification.

    My natural inclination would have been to use a for loop. Not sure how to loop over a list like this with a while loop. I'm probably just missing the obvious. You are correct that the initial inputs list is generated by splitting on a delimiter. The length of this list can be variable and I then need to add "<" and ">\n" to each end as well as "</" and ">\n" to complete the tag and then add in data within the tag.