Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Set Ip Address As 10.30.20.1 Write A Script To Replace The 30 With 40?

Answer»

here you can do this in multiple WAYS:

regsub 30 $data 40 a puts $a this will give you the REPLACED STRING.

string REPLACE $data 3 4 40 this ALSO will give you the replaced.

here you can do this in multiple ways:

regsub 30 $data 40 a puts $a this will give you the replaced string.

string replace $data 3 4 40 this also will give you the replaced.

2.

How To Check Whether A String Is Palindrome Or Not Using Tcl Script?

Answer»

Code for the above pseudo code.Check if it WORKS!!!!!

gets stdin a

set len [ string LENGTH $a ]

set n [ EXPR $len/2 ]

for { set i 0 } { $i < $n } { incr i 1 } {

set b [ string INDEX $a $i ]

set c [ expr $len – 1 – $i ]

set d [ string index $a $c ]

if {$b != $d} {

puts “not a palindrome”

exit

}

}

puts “Palindrome”

Code for the above pseudo code.Check if it works!!!!!

gets stdin a

set len [ string length $a ]

set n [ expr $len/2 ]

for { set i 0 } { $i < $n } { incr i 1 } {

set b [ string index $a $i ]

set c [ expr $len – 1 – $i ]

set d [ string index $a $c ]

if {$b != $d} {

puts “not a palindrome”

exit

}

}

puts “Palindrome”

3.

How Do You Find The Length Of A String Without Using String Length Command In Tcl?

Answer»

SET str “lenghtofthisstring”

set len 0

set list1 [ split $str “” ]

foreach VALUE $list1 {

incr len

}

puts $len

set str “lenghtofthisstring”

set len 0

set list1 [ split $str “” ]

foreach value $list1 {

incr len

}

puts $len

4.

How To Swap 30 &amp; 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

5.

How To Extract “information” From “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb” In Tcl Using A Single Command?

Answer»

% SET

a “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb”

ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb

% set b [string trimleft $a “abc”]

informationabcaaaaaabbbbbbbccbb

% set C [string trimright $b “abc”]

INFORMATION

(OR)

% set output [string trimright [string trimleft

$a “abc”] “abc”]

information

%

1.Value

% set

a “ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb”

ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb

% set b [string trimleft $a “abc”]

informationabcaaaaaabbbbbbbccbb

% set c [string trimright $b “abc”]

information

(OR)

% set output [string trimright [string trimleft

$a “abc”] “abc”]

information

%

1.Value

6.

How Increment A Character? For Example, I Give A And I Should Get B?

Answer»

L set CHARACTER “a”

set incremented_char [format %C [expr {[SCAN $character %c]+1}]] puts “Character before incrementing ‘$character’ : After incrementing ‘$incremented_char'”.

L set character “a”

set incremented_char [format %c [expr {[scan $character %c]+1}]] puts “Character before incrementing ‘$character’ : After incrementing ‘$incremented_char'”.

7.

How To Run A Package In Tcl ?

Answer»

source <package_name&GT; (or) PACKAGE require <NAME>

source <package_name> (or) package require <name>

8.

How To Increment Eacl Element In A List? Eg: Incrlist {1 2 3} =&gt;2 3 4?

Answer»

// it works like incrlist 5 6 7 =>> 6 7 8

PROC incrlist ARGS {

set s 0

FOREACH s $args {

incr s 1

puts $s

}

}

//for list

proc incrlist list {

set s 0

foreach s $list {

incr s 1

puts $s

}

}

// it works like incrlist 5 6 7 =>> 6 7 8

proc incrlist args {

set s 0

foreach s $args {

incr s 1

puts $s

}

}

//for list

proc incrlist list {

set s 0

foreach s $list {

incr s 1

puts $s

}

}

9.

How Tcl Works?

Answer»

Tcl takes the ARGUMENT as a FILE and try to READ the file. TCL STORES the file in memory and reads the file Line by Line and try to validate/compile. TCL provides the output and release the memory.

Tcl takes the Argument as a file and try to read the file. TCL stores the file in memory and reads the file Line by Line and try to validate/compile. TCL provides the output and release the memory.

10.

What Is Tcl?

Answer»

Tcl (Tool Command LANGUAGE) is a very powerful but easy to LEARN dynamic programming language, suitable for a very wide range of uses, including web and desktop APPLICATIONS, networking, administration, testing and many more. Open SOURCE and business-friendly, Tcl is a mature yet evolving language that is truly cross platform (windows,all flavors of linux,macintosh), easily deployed and HIGHLY extensible.

Tcl (Tool Command Language) is a very powerful but easy to learn dynamic programming language, suitable for a very wide range of uses, including web and desktop applications, networking, administration, testing and many more. Open source and business-friendly, Tcl is a mature yet evolving language that is truly cross platform (windows,all flavors of linux,macintosh), easily deployed and highly extensible.