Let's say we have input strings with varying character combinations, such as:
123ee4978124e340862e7352e442we34ts8034luio29752o93eweqwt27sfs59395239sfe384928% ai*4et8!sur*ysnvo546wet*ywugh)oeigh*(wahfiwnegi45oehs*klgv'niwu75*3tsjkg;ninuw% 9.368e-03, 0.3846e-045, 238476.9734, 1,00,000.000e+0, -3.8746e+006, 23.0000874% The enormous elephant was enranged by the sight of his savage captors carrying their ropes% , axes and huge iron-barred cages.%
Let us also assume that our optional token is
e. That is, we would like to 'look for' every instance of
e in any/all input string/number elements, in order to perform some formatting/replacing operations. For instance, let's assume that we'd like to replace every instance of
e with a blank space!
Given this problem, what would be the most efficient TeX/ LaTeX -based method to search for such an optional token from the given input?
Note: In this question, I am not including any further operations the user may or may not wish to perform once every instance of the optional token has been 'looked for'. However, if for demonstration purposes, some sort of post-search operation is necessary, then it would be a bonus!
When the experience with TeX/ LaTeX -based parsing is concerned, I am an 'entry-level TeX user', at best. Therefore, please consider the following:
- The approach should be sufficiently generic.
- Kindly provide TeX/ LaTeX -based solutions. LuaTeX/ XeTeX -based solutions are not preferable, as I'd rather not get confused with new syntax.
- Prospective solutions must consider the limited knowledge, understanding and abilities of an 'entry-level TeX/ LaTeX user' and therefore, in-line comments and brief explanations regarding the code behaviour would be most helpful!
- Updated: As far as possible, kindly provide solutions that do not
use any additional packages dedicated to string-parsing (e.g.
xstring). For reasons, see the update given below.
Many thanks in advance! :)
UPDATE: Perhaps I'm breaking some kind of rule here, by posting this Q-update after @HeikoOberdiek has posted an answer, nonetheless, here it is.
This update isn't intended to disregard @Heiko's answer in any way, because I understand the reasons behind his suggestions. However, his suggestion that beginners should just stick to the
xstringpackage doesn't really work for me, since -
- I'm already familiar with
- As a beginner, I am more keen on learning some basic TeX/LaTeX parsing techniques from more experienced users, so that I can improve my TeX abilities.
Therefore, I've added an extra suggestion to the above list via this update. I hope that's OK.