I have a problem where I seem to be unable to replace a string that is the output of a command.
In my document I call the \outerfunction
with an argument that is actually a list of key/value pairs. (This is something I cannot change because the command as it is is used throughout the entire document)
In the \outerfunction
the values list items are stripped off and the keys separated by a separation code (-SEPARATOR-
) and enclosed in parentheses.
The problem is that I want to get rid of the last separation code before the closing parenthesis. I tried the \replace
function as provided in this post, I also tried the \StrSubstitute
function from the xstring
package without success.
When I insert the source string hard-coded into any of these functions the replacement works. I fail to understand the difference or to find a way to a solution. Can someone help me on this please?
Example:
\documentclass{article}
\usepackage{stringstrings}
\usepackage{xstring}
\usepackage{xparse}
\def\replace#1#2#3{%
\def\tmp##1#2{##1#3\tmp}%
\tmp#1\stopreplace#2\stopreplace}
\def\stopreplace#1\stopreplace{}
\newcommand{\processlist}[1]
{%
\noexpandarg%
\ifx\listfinish#1\empty%
%\else\texttt{\stringpart{#1}--}\expandafter\processlist%
\else\texttt{#1-SEPARATOR-}\expandafter\processlist%
\fi%
}
\newcommand\outerfunction[2][\relax]
{%
arg1: #1\\
arg2: #2\\
\def\listfinish{#1}%
\long\def\listact{}%
\replace{(\processlist#2\listfinish)}{-SEPARATOR-)}{)}\\%this does nothing
\StrSubstitute{(\processlist#2\listfinish)}{-SEPARATOR-)}{)}\\%this does nothing
%using the text from the output for the StrSubstitute command works
\StrSubstitute{(key1 - value1-SEPARATOR-key2 - value2-SEPARATOR-key3 - value3-SEPARATOR-)}{-SEPARATOR-)}{)}
}
\begin{document}
\outerfunction
{
{key1 - value1}
{key2 - value2}
{key3 - value3}
}
\end{document}
(key1)-SEPARATOR-(key2)-SEPARATOR-(key3)
? Otherwise, please be more specific on what you expect.