How do you check whether a string is palindrome or not using TCL script?

Answer Posted / swinful

Let me know what you think. The above solutions are just as good, but this one is short and simple. It is pretty much self explanatory. Hope you like:)

--- cut----
proc IsPalindrome { theString } {
set theString [string trim [string tolower $theString]]
for {set i 0} {$i<[string length $theString]} {incr i} {
if { [string compare "[string index $theString end-$i]" "[string index $theString $i]"] != 0 } {
puts "false"; exit 2
} else { puts "true"; exit 0 }
}
}

IsPalindrome '[lindex $argv 0]'
--- cut----

You can put the above into a script and run it, supplying a command-line argument.

Cheers
-swinful

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi all, Is there any certification exams available for TCL and Perl. If so please let me know, my mailid is vpbharathi@gmail.com. Thanks in advance, Bharathi.P

2529