[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: determining length of string
From: |
John Graham-Cumming |
Subject: |
Re: determining length of string |
Date: |
Tue, 10 Apr 2007 09:20:46 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John Graham-Cumming wrote:
> Left as an exercise for the reader :-)
OK. That was a little harsh. Here's a strchop function that can
truncate an arbitrary string to a certain number of characters:
characters := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
characters += a b c d e f g h i j k l m n o p q r s t u v w x y z
characters += 0 1 2 3 4 5 6 7 8 9
characters += ` ~ ! @ \# $ % ^ & * ( ) - _ = +
characters += { } [ ] \ : ; ' " < > , . / ? |
sp :=
sp +=
strchop = $(strip $(eval __temp := $(subst $(sp),|,$1))$(foreach
a,$(characters),$(eval __temp := $$(subst $$a,$$a ,$(__temp))))$(eval
__temp := $(wordlist 1,$2,$(__temp)))$(eval __temp := $$(foreach
a,$(__temp),$$a))$(eval __temp := $$(subst |, ,$(__temp))))$(__temp)
X = the quick brown
$(warning x$(call strchop,$(X),4)x)
Note that the string _must not_ contain the | character.
John.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGGzrOLphrp73n/hARAqdbAJ9Zi5nsoNLmXC7nR5OchqqW9JoTiQCfcZ6O
sQIXwNWawx+RwNQe8bQdBbA=
=lRt4
-----END PGP SIGNATURE-----