Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Last Character

Status
Not open for further replies.

GRonken

Programmer
Oct 30, 2003
26
0
0
US
I want to compare the last character in a line. How do I grab that character into a varible?
 
assuming the line is already in a string, say, s, then
set lc [string range $s end end]


Bob Rashkin
rrashkin@csc.com
 
Maybe simpler and quicker:
set lc [string index $s end]

ulis
 
Thanks - Both actiually work, it is nice to have a couple of examples, makes learning tcl much easier. I would be interested in your comments regarding best books, internet resources, comparison to AWK as a scripting tool, TclPro ....
 
Awks better for fast and dirty processing and for
convenience you can't beat things like:
Code:
awk ' {var += $3} END {printf "Sum total is %d\n", int(var)}'

In tcl you'd have to split the columns manually, then
aggregate the numbers in an array or list, then sum
them up using expr. Bleah.
If you are a linux guy you may want to take a look
at the old xconfig script for selecting options to
recompile your kernel.
There were some incredible hacks in that script
using tcl,sed and awk. ;)

As far as event oriented programming, easy socket
programming, Gui dev, etc..TCL is one of the coolest
and simplest languages to use and learn.
The best source for tcl is the wiki:
and comp.lang.tcl.

There is a good awk forum here at tek-tips and
comp.lang.awk is the experts repository.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top