Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TCL: How do I count how many letters in a string?

1,866 views
Skip to first unread message

The Last Gunslinger

unread,
Jan 28, 1994, 5:25:23 AM1/28/94
to
Hwo does one count the letters in a string? For example if I wanted to
count how many letters composed the body of this article?
I can't seem to find such a function anywhere. Also, how do I count how
many lines are in a large string? (say dp_receive input from a telnet socket)


- liem
--
=======[rol...@cac.washington.edu]=====[The Last Gunslinger]==================
Outside of a dog, computers are a man's best | UCS Consulting
friend, inside a dog it's too dark to type. | UW Ice Hockey
http://topquark.cecer.army.mil/~roland/ | Linux/WWW/tcl/tk/LOTRmush

David DeGeorge

unread,
Jan 30, 1994, 9:59:09 AM1/30/94
to
If the variable a contains the text to be counted then the following
seems to work:
llength [split $a ""]
David

Sanjay Ghemawat

unread,
Jan 30, 1994, 10:11:31 AM1/30/94
to

From the man-page for "string" --

string length string
Returns a decimal string giving the number of characters in string.

-Sanjay Ghemawat
--
Sanjay Ghemawat
san...@lcs.mit.edu

Bill Burdick

unread,
Jan 31, 1994, 9:39:58 AM1/31/94
to
This will count the number of *letters* in string...

#remove all nonletters from string
regsub {[^A-Za-z]} $string "" result
#set len to length of result
set len [string length $result]
--

-- Bill Burdick
bur...@ars.rtp.nc.us

Hume Smith

unread,
Jan 31, 1994, 4:59:50 PM1/31/94
to
>>>>> On 28 Jan 1994 10:25:23 GMT, rol...@cac.washington.edu (The Last Gunslinger) said:
TLG> NNTP-Posting-Host: goren.u.washington.edu

TLG> Hwo does one count the letters in a string? For example if I wanted to
TLG> count how many letters composed the body of this article?

length of string:
string length $var

number of letters only:
regsub {[^a-zA-Z]+} $a {} b
string length $b

TLG> I can't seem to find such a function anywhere. Also, how do I count how
TLG> many lines are in a large string? (say dp_receive input from a telnet socket)

llength [split $a \n]

regsub \[^\n\] $a {} b
string length $b

--
Hume Smith 850...@dragon.acadiau.ca
"...it's the feeling so sunny when you're squeezing a bunny..."
the only Stimpy line i like: "You broke it! You broke it!"

0 new messages