If I'm right about your question, you have read in a string from a text file. That string contains: "111111","10/21/00",1,10,"10101",111,13
quotes, commas, and all. Right so far?
I think the best thing for you at this point is to "split" the string into a list using the comma as the delimiter character.
Let's say you read a line from the file into a string variable, lineString. So the value of "lineString" is "111111","10/21/00",1,10,"10101",111,13.
Now, split lineString on commas and put the result in a list named lineList:
set lineList [split $lineString ,]
If you wanted to lose the "s, I'd do that first using "string map":
set lineString [string map {\" ""} $lineString]
Now, if you still want to know the number of commas in the original string, that's equal to the number of elements in the list minus 1:
expr {[llength $lineList]-1}
To find the index of the element whose value is, say, 10/21/00, use "lsearch":
set val1ix [lsearch $lineList 10/21/00]
To find the value of the 2nd element, use "lindex":
set val1 [lindex $lineList 1]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.