[Tex/LaTex] Replace asterisk with nothing in string

stringssubstitutiontables

I have a function which grabs cells out of a table and returns them. Many of these cells end with two asterisks, and I would not like these returned from the function if they are present. For example:

% Function to get data
\def\getdata#1#2{%
\pgfplotstablegetelem{#1}{#2}\of{\table}\pgfplotsretval%
}

If this returns a value such as "2.3**", I would like "2.3". Thanks, I assume this is rather straightforward.

Best Answer

pgfplotstable offers a possibility to ignore a list of characters while the data is being read from the table via ignore chars={} key.

\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents*}{scientists.csv}
name,surname,age
Alb*ert,Einstein**,133
Marie**,Curie,145
Thomas,Edis**on,165**
\end{filecontents*}

\pgfplotstableread[col sep=comma,ignore chars={*}]{scientists.csv}\mytable
\def\getcell#1#2#3{%
\pgfplotstablegetelem{#1}{#2}\of{#3}\pgfplotsretval%
}
\begin{document}
\pgfplotstabletypeset[
    string type,
    columns/name/.style={column name=Name, column type={|l}},
    columns/surname/.style={column name=Surname, column type={|l}},
    columns/age/.style={column name=Age, column type={|c|}},
    every head row/.style={before row=\hline,after row=\hline},
    every last row/.style={after row=\hline},
    ]\mytable

\bigskip
\getcell{0}{name}{\mytable} \getcell{0}{surname}{\mytable} is \getcell{0}{age}{\mytable} 
years old. \getcell{1}{name}{\mytable} \getcell{1}{surname}{\mytable} is 
\getcell{1}{age}{\mytable} years old. But \getcell{2}{name}{\mytable} 
\getcell{2}{surname}{\mytable} is still older, he is \getcell{2}{age}{\mytable} years old.
\end{document}

enter image description here

However, one should be careful since this method eats every instance of asterisk. For example Alb*ert is also modified. So one must be careful (x2).