I want to use a part of the filename as a counter:
First I try to use a variable as a counter:
mwe_aa_03.tex:
\documentclass{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\newcommand{\thatispage}{3}
\addtocounter{section}{\thatispage}
\ihead{Page \thatispage }
\begin{document}
\section{section}
but this should be section 3
\end{document}
this works, but now I want to use the filename as a number:
mwe_bb_03.tex:
\documentclass{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{xstring}
\newcommand{\fancypagenumber}{\StrBehind[2]{\jobname}{\string_} }
\addtocounter{section}{\fancypagenumber}
\ihead{Page \fancypagenumber }
\begin{document}
\section{section}
but this should be section 3
\end{document}
which does not work ("Missing number, treated as zero").
Can you explain what I am doing wrong? How can I make this string becomming a number?

\begingroup\edef\x{\endgroup\def\noexpand\removeuntilsecondunderscore#1\string_#2\string_{}}\xand then\edef\fancypagenumber{\expandafter\removeuntilsecondunderscore\jobname}. – Manuel Nov 11 '17 at 16:36