Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

LOOPS

puts "Hello World!"
set a 20
set b 30
set c 30

puts [string compare a b]
if {[string compare b c] == 0} {
    puts "string \'a\' and \'b\' are same.";
}

if {[string compare a b] == -1} {
   puts "string \'a\' comes before \'b\'.";
}

if {[string compare b a] == 1} {
    puts "string \'b\' comes after \'a\'.";
}


set a "hello world"
set b  "o"
puts "first occurrence of $b in a"
puts [string first $b $a]
puts "character at index 0 in a"
puts [string index $a 0]
puts "last occurance of $b in a"
puts [string last $b $a]
puts  "word end  index  in a" 
puts [string wordend  $a 20]
puts "word start index in a"
puts [string wordstart $a 20]




set s1 "hello world"
set s2 "world"
puts "trim right $s2 in $s1"
puts [string trimright $s1 $s2]

set s2 "hello"
puts "trim right $s2 in $s1"
puts [string trimleft $s1 $s2]

set s1 " hello world "
set s2 " "
puts "trim characters s1 on both sides of s2"
puts [string trim $s1 $s2]


\n

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.