Reputation: 77
Hello I am trying to cut a string in my script and set them to two different variables in my script.
date_string = "OCT-09-1956"
What I want to do is take that date_string variable above and split it into two different variables a month variable and a year variable.
Upvotes: 0
Views: 502
Reputation: 1863
Some may tell you that regexp
is the solution here.
I recommend using the split
command to create a new list and then assign new variables from the list elements. I like to avoid regexes unless they're really necessary.
set date_string "OCT-09-1956"
lassign [split $date_string "-"] month day year
puts "The month is $month"
puts "The year is $year"
Upvotes: 2