Forum Discussion
Matt_Breedlove_
Nimbostratus
May 23, 2014Splitting a delimited string into multiple variables in one line with TCL split versus GetField
This is a breeze to do in perl...
$string=="blah1-blah2-blah3";
($field1, $field2, $field3) = split(/-/,$string,3);
In TCL there is the split function, but I don't see any references to assig...
Kevin_Stewart
Employee
May 23, 2014Not sure I completely understand, the result of a tcl split is a list:
set str "blah1-blah2-blah3"
set fields [split $str "-"]
You can then use this list as is, completely indexable:
log local0. [lindex $fields 0]
=blah1
The getfield command is indeed an iRule-optimized "lindex-split"
set str "blah1-blah2-blah"
log local0. [lindex [split $str "-"] 1]
=blah2
As far as proxy are concerned, a tcl list is really just an indexable string, so it's straight forward to return a list from a proc call:
proc test { var } {
return [split $var "-"]
}
set str "blah1-blah2-blah3"
set doit [call test $str]
log local0. [lindex $doit 2]
=blah3
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects