Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!usc!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout From: eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) Newsgroups: comp.text.tex Subject: Re: Want to extract words from a string Message-ID: <1991Jan30.235332.18606@csrd.uiuc.edu> Date: 30 Jan 91 23:53:32 GMT References: <1991Jan30.213501.10838@midway.uchicago.edu> Sender: news@csrd.uiuc.edu (news) Organization: UIUC Center for Supercomputing Research and Development Lines: 30 jeff@zem.uchicago.edu (Jeff Adler) writes: >Suppose I have a string consisting of words separated by blanks. >I would like a macro which returns the last word of the string, >Example: > \lastword{one two three four} yields four \def\lastword#1{\def\compare{zzz}% \xlastword#1 zzz } % ^ ^ two spaces \def\xlastword#1 #2 {% % ^ ^ corresponding to these \def\test{#2}% \ifx\test\compare #1% \else \expandafter\xlastword \fi #2 } % ^ significant space >and another macro which returns everything else. replace \ifx line by \ifx\test\compare \accu \else \edef\accu{\accu #1 }% \expandafter\xlastwork \fi #2 } and add \def\accu{ } somewhere in the beginning. Victor.