Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!cernvax!chx400!hslrswi!naz From: naz@hslrswi.hasler.ascom.ch (Norman H. Azadian) Newsgroups: comp.lang.icon Subject: a small problem Keywords: string scanning Message-ID: <1716@hslrswi.hasler.ascom.ch> Date: 9 Jan 91 12:20:56 GMT Organization: Hasler AG Lines: 36 I'm new to this string scanning stuff, and I'm having difficulty finding a nice clean way to perform the following simple calculation. I have a string, S, in which I want to know the number of characters which are used by any of several known substrings. There is no problem with overlapping substrings. Here is a small example to show exactly what I mean: count := 0 every s ? find ("whizzy" | "ding") do count +:= 1 This would do what I want if I merely wanted to count the number of occurrences of the substrings "whizzy" and "ding". However, what I want to do is know the total number of characters in s which are used for these substrings, however many times they may occur. I'm hoping to find something with an elegance approaching that of the above example. Brute force solutions need not apply. P.S. The real-life problem is that I have ANSI control sequences embedded in a string which wants to be centered. NHA --- PAPER: Norman Azadian; Hasler AG; Belpstrasse 23; 3000 Berne 14; Switzerland X.400: naz@hslrswi.hasler UUCP: ...{uunet,ukc,mcvax,...}!cernvax!hslrswi!naz VOICE: +41 31 63 2178 BITNET: naz%hslrswi.UUCP@cernvax.BITNET -- PAPER: Norman Azadian; Ascom AG; Belpstrasse 23; 3000 Berne 14; Switzerland INTERNET: naz%hslrswi.uucp@uunet.uu.net UUCP: ...{uunet,ukc,mcvax,...}!chx400!hslrswi!naz VOICE: +41 31 63 2178 BITNET: naz%hslrswi.UUCP@cernvax.BITNET