Reputation: 68
I have a list where some elements are strings where I need them to be enclosed in quotation marks.
If I iterate over the list and puts each element to the terminal the output looks correct. However, if I lindex to a specific element which is enclosed in quote marks, the quote marks disappear.
Example code:
set myList [list "BUILD_PROJ \"I have quotes\""]
foreach element $myList {
puts [lindex $element 1]
puts [lindex $element]
}
Outputs:
I have quotes
BUILD_PROJ "I have quotes"
How do I get a specific lindexed element from a list to keep its quotation marks?
Upvotes: 0
Views: 408
Reputation: 68
My bad, getting mixed up with separators. I think escaping the quotation marks was effectively giving me a list with a single element. Updated to this:
set myList [list "BUILD_PROJ" "\"I have quotes\""]
puts $myList
puts [lindex $myList 0]
puts [lindex $myList 1]
And now the output is as I expect:
BUILD_PROJ {"I have quotes"}
BUILD_PROJ
"I have quotes"
Upvotes: 0