[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: |
Mon, 09 Apr 2007 16:44:18 +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
LeJacq, Jean Pierre wrote:
> Any suggestions on how how to determine the length of
> a string with just GNU Make functions?
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 y z
characters += 0 1 2 3 4 5 6 7 8 9
strlen = $(strip $(eval __temp := $(subst $(sp),x,$1))$(foreach
a,$(characters),$(eval __temp := $$(subst $a,x,$(__temp))))$(eval __temp
:= $(subst x,x ,$(__temp)))$(words $(__temp)))
Then do: $(call strlen,$(X)) to get the length of X. Clearly, you may
need to augment the definition of characters if the string can contain
characters other than alphanumerics, but I hope that gives you an idea
of how to do it.
> If that is possible, is there a way of trimming a string
> to a desired length at either end?
Left as an exercise for the reader :-)
John.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGGlFCLphrp73n/hARAtHEAKCIcisHd7GJDmtDGfdItKjh53rVNACfbT43
EKDd/Hl43Ki9OSlvJQ+Apnw=
=iP6a
-----END PGP SIGNATURE-----