"join" will create a string from what is supposed to be a list..darko`` wrote:Assuming variable $text contains your line:
set mylist [join $text] ### Create a proper list assuming a whitespace is a delimiter
set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]
The second line looks a bit scary because it need's to get rid of data1 and consider only text1 text2 ect...
Code: Select all
set mylist [split $text]
Code: Select all
set mylist [split $text "*"]
Code: Select all
set mylist [join $text] ### Create a proper list assuming a whitespace is a delimiter
Code: Select all
set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]
Code: Select all
set $filename = "data.txt" // Change to filename of data file
set $fs [open $filename r]
gets $fs text
close $fs
set mylist [split $text "*"]
set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]
Code: Select all
set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]
Code: Select all
set mylist [split $text "*"]
set myrandomtext [lindex $mylist [expr [rand [llength $mylist]] + 1]]
Code: Select all
set mylist [lrange [split $text "*"] 1 end]
set myrandomtext [lindex $mylist [rand [llength $mylist]]]