I am in a situation to replace many characters from a sentence. In the working example attached below, command relaceB replaces backslash and command replaceA replaces many other characters like **, /* etc. But I am unable to combine both the commands together to form a single new command (which replaces- *,/,\ etc). Does anybody know how to fix it?
\documentclass{article}
\usepackage{xparse}
%Removing other characters
\ExplSyntaxOn
\tl_new:N \l_azor_string_tl
\cs_new_protected:Npn \azor_replace_norsk:n #1
{
\tl_set:Nn \l_azor_string_tl { #1 }
\tl_replace_all:Nnn \l_azor_string_tl { / } { -- }
\tl_replace_all:Nnn \l_azor_string_tl { ? } { -- }
\tl_replace_all:Nnn \l_azor_string_tl { * } { --}
\tl_use:N \l_azor_string_tl
}
\NewDocumentCommand \replaceA { m }
{
\azor_replace_norsk:n { #1 }
}
\ExplSyntaxOff
%Removing backslash
\ExplSyntaxOn
\NewDocumentCommand{\replaceB}{m}
{
\tl_set:Nn \l_tmpa_tl { #1 }
\regex_replace_all:nnN { \cC. } { \c{cs_to_str:N} \0 } \l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
\begin{document}
\replaceA{a/b*c} %Works
\replaceB{d\e} %Works
\replaceA{\replaceB{a/b*cd\e}} %Does not work
\end{document}
\replace
which does\replaceA{\replaceB{#1}}
or as in you want them to work in this nested way?\replaceresult
:\replaceB{a/b*cd\e}
does not typeset but stores in\replaceresult
.\expandafter\replaceA\expandafter{\replaceresult}
will now act on that and the new\replaceresult
is what you want. you can also define them to expand once, so you don't need\expandafter
. Also, simplest might be to define a third command\replaceC
doing all your replacements at once, if you want to stick to your initial way of doing things