0

I have a main-table Data.txt with some contents

col1, col2, col3
a, b, c
x, y, z
aaa, abc, xyz

where I want to replace some strings.

If I say

\pgfplotsinvokeforeach{x,y,z}{
\pgfplotstableset{string replace={#1}{was #1}  }  
} % works

it works well.

But if I use another table MetaData.txt

actual, target
a, 1
b, 2
c, 3

with which I want to replace 'actual' with 'target' in the main-table

\pgfplotsinvokeforeach{0,...,2}{%
\pgfmathtruncatemacro\n{#1}
\pgfplotstablegetelem{\n}{actual}\of\MetaData%
\xdef\actual{\pgfplotsretval}%
\pgfplotstablegetelem{\n}{target}\of\MetaData%
\xdef\target{\pgfplotsretval}%
Let's replace: \actual, \target
% Problem here: 
\pgfplotstableset{  string replace={\actual}{\target}  }  % works not!
}% 

the string replace of the main-table does not work!

Note that these are arbitrary examples, instead of replacing 'a' with '1' it could be also the replacement from 'u' with 'whatever'.

What do I have to do?

enter image description here

\begin{filecontents}[overwrite]{\jobname-Data.txt}
col1, col2, col3
a, b, c
x, y, z
aaa, abc, xyz
\end{filecontents}

\begin{filecontents}[overwrite]{\jobname-MetaData.txt}
actual, target
a, 1
b, 2
c, 3
\end{filecontents}

\documentclass[]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

\pgfplotstableset{string type, col sep=comma}
\begin{document}
\section{Original Table}
\pgfplotstabletypeset[]{\jobname-Data.txt}

\section{String Replaced Table}
\pgfplotsinvokeforeach{x,y,z}{
\pgfplotstableset{string replace={#1}{was #1}  }  
} % works

\pgfplotstableread[]{\jobname-MetaData.txt}\MetaData

% Problem: 
\pgfplotsinvokeforeach{0,...,2}{%
\pgfmathtruncatemacro\n{#1}

\pgfplotstablegetelem{\n}{actual}\of\MetaData%
\xdef\actual{\pgfplotsretval}%
\pgfplotstablegetelem{\n}{target}\of\MetaData%
\xdef\target{\pgfplotsretval}%
Let's replace: \actual, \target
% Problem here: 
\pgfplotstableset{  string replace={\actual}{\target}  }  % works not!
}% 

\bigskip
\pgfplotstabletypeset[]{\jobname-Data.txt}
\end{document}
0

1 Answer 1

0

All time the same. :)

% Problem here solved: 
\edef\temp{\noexpand\pgfplotstableset{  string replace={\actual}{\target}  }  }
\temp

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.