InterviewSolution
| 1. |
How To Swap 30 & 40 In Ip Address 192.30.40.1 Using Tcl Script? |
|
Answer» There are three solutions: set a 192.30.40.1 set b [ string range $a 3 4 ] set c [ string range $a 6 7 ] set d [ string REPLACE $a 3 4 $c ] set e [ string replace $d 6 7 $b] puts $e (OR) set a 192.30.40.1 set b [ split $a .] set u [lindex $b 0] set v [lindex $b 3] set X [lindex $b 1] set y [lindex $b 2] set z [JOIN “$u $y $x $v” .] puts $z (OR) set ip 192.30.40.1 regexp {([0-9]+.)([0-9]+.)([0-9]+.)([0-9]+)} $ip match 1ST 2nd 3rd 4th append new_ip $1st $3rd $2nd $4th puts $new_ip There are three solutions: set a 192.30.40.1 set b [ string range $a 3 4 ] set c [ string range $a 6 7 ] set d [ string replace $a 3 4 $c ] set e [ string replace $d 6 7 $b] puts $e (OR) set a 192.30.40.1 set b [ split $a .] set u [lindex $b 0] set v [lindex $b 3] set x [lindex $b 1] set y [lindex $b 2] set z [join “$u $y $x $v” .] puts $z (OR) set ip 192.30.40.1 regexp {([0-9]+.)([0-9]+.)([0-9]+.)([0-9]+)} $ip match 1st 2nd 3rd 4th append new_ip $1st $3rd $2nd $4th puts $new_ip |
|