# Append to an argument

I have a command that receives some argument, like:

\newcommand{\myappend}[1]{
\ifthenelse{\equal{#1}{aaaBB}}{\dothis}{\dothat}
}


Assume that the argument is 'aaa'. How to append (inside the command) 'BB' to #1, that is, how to edit #1 ?

-
You have your example set up as an \ifthenelse, but question posits no such branching, but merely asks how to append to an argument, such as \def\myappend#1{#1BB} –  Steven B. Segletes Mar 3 '14 at 2:19
I read your question several times, but I can't understand what you're asking. Isn't \ifthenelse{\equal{#1BB}{aaaBB}} what you're looking for? –  egreg Mar 3 '14 at 7:47

## 3 Answers

With \ifstrequal from etoolbox:

\documentclass{article}
\usepackage{etoolbox}
\newcommand{\myappend}[1]{%
\ifstrequal{#1}{aaaBB}{}{aaaBB}
}%
\begin{document}
\myappend{aaa}
\end{document}


And

\documentclass{article}
\usepackage{ifthen}
\newcommand{\myappend}[1]{%
\ifthenelse{\equal{#1}{aaaBB}}{}{aaaBB}
}%
\begin{document}
\myappend{aaa}
\end{document}

-

I am not sure I understood the question. Here are two options: the first one, using an auxiliary command to add "BB" to #1 and the second one does the same but using \StrSubstitute from the xstring package:

\documentclass{article}
\usepackage{ifthen}
\usepackage{xstring}

\def\dothis{this}
\def\dothat{that}

\newcommand\myappend[1]{%
\def\x{#1BB}%
\ifthenelse{\equal{\x}{aaaBB}}{\dothis}{\dothat}%
}

\newcommand\myappendi[1]{%
\StrSubstitute{#1}{aaa}{aaaBB}[\x]%
\ifthenelse{\equal{\x}{aaaBB}}{\dothis}{\dothat}%
}

\begin{document}

\myappend{aaa}\ \myappend{aaaBB}

\myappendi{aaa}\ \myappendi{aaaBB}

\end{document}


-

String comparison under pdfTeX is made easily possible via the primitive \pdfstrcmp:

\documentclass{article}
% \pdfstrcmp{<string1>}{<string2>}
% \pdfstrcmp compares two strings and expands to 0 if the strings are equal, to -1 if the first string
%   ranks before the second, and to 1 otherwise
\newcommand{\myappend}[1]{%
\ifnum\pdfstrcmp{#1}{aaa}=0
This% Strings are equal
\else
That% Strings are not equal
\fi%
}
\begin{document}
\myappend{aab} % That
\myappend{aaA} % That
\myappend{aaa} % This
\myappend{AAa} % That

\newcommand{\aaa}{aaa}
\myappend{\aaa} % This
\end{document}

-