# Usage of \IfEndWith and \StrGobbleRight Inserting Spaces [closed]

## 2013-03-06: Update:

It seems that there was a recent update to xstring which resolved this problem. Just updated all packages and the MWE below now correctly produces:

It seems as if I am having a problem understanding \StrGobbleRight. The intent of the the \RemoveTrailingSpace is to do what it says, that is remove trailing space on the right. But the MWE seems to be inserting space on the left:

This is part of a much bigger macro so I use \SearchTarget later on, but don't want this spacing???

## Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{xstring}

\newcommand*{\RemoveTrailingSpace}[1]{%
\IfEndWith{#1}{\space}{%
\StrGobbleRight{#1}{1}[\SearchTarget]%
}{%
\def\SearchTarget{#1}%
}%
\SearchTarget%
}

\begin{document}\noindent
X\RemoveTrailingSpace{YYY}Z

\noindent
X\RemoveTrailingSpace{ YYY}Z

\noindent
X\RemoveTrailingSpace{YYY }Z

\noindent
X\RemoveTrailingSpace{YYY     }Z
\end{document}
-
 The problem was in the definition of \@cs@removefirstsyntaxunit, line 209f.: An opening brace at the end of the line. – Qrrbrbirlbel Mar 7 at 2:55

## closed as too localized by Peter Grill, Speravir, Kurt, Qrrbrbirlbel, lockstepMar 7 at 3:22

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.