Append unique characters read from filecontents to a stringfrom string to commandRead single value from a tableA command for making a string of charactersStrip control characters from tokenCommand to count characters in a specified stringGenerate Tikz tree from filecontentsHow to repeat over all characters in a string?Remove par from stringApplying and doing math on two functions read from a file using pgfCreating a unique list from two tables read from filecontents
Problem with estimating a sequence with intuition
Make me a minimum magic sum
Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?
All of my Firefox add-ons been disabled suddenly, how can I re-enable them?
Debian 9 server no sshd in auth.log
Can a good but unremarkable PhD student become an accomplished professor?
My large rocket is still flipping over
What does のそ mean on this picture?
What detail can Hubble see on Mars?
How to use awk to extract data from a file based on the content of another file?
Picking a theme as a discovery writer
Convert Numbers To Emoji Math
How to speed up large double sums in a table?
Books of scary stories with two or three plots each
What happens if I accidentally leave an app running and click "Install Now" in Software Updater?
Was there a dinosaur-counter in the original Jurassic Park movie?
How did the Force make Luke hard to hit in the Battle of Yavin?
If an enemy monster charms one PC and tells them to attack a second PC, and then the second PC charms the monster, what happens?
How long did it take Captain Marvel to travel to Earth?
Has the United States ever had a non-Christian President?
Does Thanos's ship land in the middle of the battlefield in "Avengers: Endgame"?
Why would a military not separate its forces into different branches?
Installing Debian 10, upgrade to stable later?
Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?
Append unique characters read from filecontents to a string
from string to commandRead single value from a tableA command for making a string of charactersStrip control characters from tokenCommand to count characters in a specified stringGenerate Tikz tree from filecontentsHow to repeat over all characters in a string?Remove par from stringApplying and doing math on two functions read from a file using pgfCreating a unique list from two tables read from filecontents
I have a list of 2-character strings that is read from table, e.g.
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
I want to create a string that will contain unique 2-character strings. The result should be
SLSKMCAAPTUP
Here is what I've come up so far.
documentclass[10pt,a4paper]article
usepackagexparse
usepackagexstring
usepackagefilecontents
usepackagepgfplotstable
usepackageifthen
defmystring % initialize
defextendmystring#1#2edefmystring#1mystring#2
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
mystring
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
deftempstringpgfplotsretval
extendmystringtempstring
Display concatenated string
mystring
enddocument
but mystring value is empty after each iteration.
macros pgfplotstable strings filecontents
add a comment |
I have a list of 2-character strings that is read from table, e.g.
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
I want to create a string that will contain unique 2-character strings. The result should be
SLSKMCAAPTUP
Here is what I've come up so far.
documentclass[10pt,a4paper]article
usepackagexparse
usepackagexstring
usepackagefilecontents
usepackagepgfplotstable
usepackageifthen
defmystring % initialize
defextendmystring#1#2edefmystring#1mystring#2
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
mystring
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
deftempstringpgfplotsretval
extendmystringtempstring
Display concatenated string
mystring
enddocument
but mystring value is empty after each iteration.
macros pgfplotstable strings filecontents
1
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way yourextendmystring
macro is designed you can prefix it withglobal
(ie,globalextendmystringtempstring
) and it will work.
– Phelype Oleinik
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago
add a comment |
I have a list of 2-character strings that is read from table, e.g.
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
I want to create a string that will contain unique 2-character strings. The result should be
SLSKMCAAPTUP
Here is what I've come up so far.
documentclass[10pt,a4paper]article
usepackagexparse
usepackagexstring
usepackagefilecontents
usepackagepgfplotstable
usepackageifthen
defmystring % initialize
defextendmystring#1#2edefmystring#1mystring#2
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
mystring
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
deftempstringpgfplotsretval
extendmystringtempstring
Display concatenated string
mystring
enddocument
but mystring value is empty after each iteration.
macros pgfplotstable strings filecontents
I have a list of 2-character strings that is read from table, e.g.
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
I want to create a string that will contain unique 2-character strings. The result should be
SLSKMCAAPTUP
Here is what I've come up so far.
documentclass[10pt,a4paper]article
usepackagexparse
usepackagexstring
usepackagefilecontents
usepackagepgfplotstable
usepackageifthen
defmystring % initialize
defextendmystring#1#2edefmystring#1mystring#2
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
mystring
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
deftempstringpgfplotsretval
extendmystringtempstring
Display concatenated string
mystring
enddocument
but mystring value is empty after each iteration.
macros pgfplotstable strings filecontents
macros pgfplotstable strings filecontents
asked 7 hours ago
Almic7Almic7
304
304
1
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way yourextendmystring
macro is designed you can prefix it withglobal
(ie,globalextendmystringtempstring
) and it will work.
– Phelype Oleinik
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago
add a comment |
1
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way yourextendmystring
macro is designed you can prefix it withglobal
(ie,globalextendmystringtempstring
) and it will work.
– Phelype Oleinik
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago
1
1
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way your extendmystring
macro is designed you can prefix it with global
(ie, globalextendmystringtempstring
) and it will work.– Phelype Oleinik
7 hours ago
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way your extendmystring
macro is designed you can prefix it with global
(ie, globalextendmystringtempstring
) and it will work.– Phelype Oleinik
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago
add a comment |
2 Answers
2
active
oldest
votes
With expl3
:
beginfilecontents*jobname.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandmakestringom
% #1 = macro to store the string in, #2 = file name
almic_makestring:n #2
IfNoValueTF #1
str_use:N l__almic_makestring_str
str_new:N #1 str_set_eq:NN #1 l__almic_makestring_str
ior_new:N g__almic_makestring_stream
str_new:N l__almic_makestring_str
seq_new:N l__almic_makestring_seq
cs_new_protected:Nn almic_makestring:n
% clear the auxiliary sequence
seq_clear:N l__almic_makestring_seq
% read the file and store the items
ior_open:Nn g__almic_makestring_stream #1
ior_str_map_inline:Nn g__almic_makestring_stream
seq_put_right:Nn l__almic_makestring_seq ##1
ior_close:N g__almic_makestring_stream
% remove the first item
seq_pop_left:NN l__almic_makestring_seq l_tmpa_tl
% remove the duplicates
seq_remove_duplicates:N l__almic_makestring_seq
%
str_set:Nx l__almic_makestring_str seq_use:Nn l__almic_makestring_seq
ExplSyntaxOff
begindocument
makestringjobname.dat
makestring[test]jobname.dat
textttmeaningtest
enddocument
add a comment |
To achieve this, you do not need anything beyond pgfplotstable.
documentclass[10pt,a4paper]article
usepackagepgfplotstable
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
ifnumk=0
xdefmyLstpgfplotsretval
xdefmystringpgfplotsretval
else
xdeftmpElOld0
edefnewelementpgfplotsretval
foreach oldelement in myLst
ifxnewelementoldelement
% typeoutduplicate
xdeftmpElOld1
fi
ifnumtmpElOld=0
xdefmyLstmyLst,pgfplotsretval
xdefmystringmystringpgfplotsretval
fi
fi
mystring
enddocument
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489369%2fappend-unique-characters-read-from-filecontents-to-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
With expl3
:
beginfilecontents*jobname.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandmakestringom
% #1 = macro to store the string in, #2 = file name
almic_makestring:n #2
IfNoValueTF #1
str_use:N l__almic_makestring_str
str_new:N #1 str_set_eq:NN #1 l__almic_makestring_str
ior_new:N g__almic_makestring_stream
str_new:N l__almic_makestring_str
seq_new:N l__almic_makestring_seq
cs_new_protected:Nn almic_makestring:n
% clear the auxiliary sequence
seq_clear:N l__almic_makestring_seq
% read the file and store the items
ior_open:Nn g__almic_makestring_stream #1
ior_str_map_inline:Nn g__almic_makestring_stream
seq_put_right:Nn l__almic_makestring_seq ##1
ior_close:N g__almic_makestring_stream
% remove the first item
seq_pop_left:NN l__almic_makestring_seq l_tmpa_tl
% remove the duplicates
seq_remove_duplicates:N l__almic_makestring_seq
%
str_set:Nx l__almic_makestring_str seq_use:Nn l__almic_makestring_seq
ExplSyntaxOff
begindocument
makestringjobname.dat
makestring[test]jobname.dat
textttmeaningtest
enddocument
add a comment |
With expl3
:
beginfilecontents*jobname.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandmakestringom
% #1 = macro to store the string in, #2 = file name
almic_makestring:n #2
IfNoValueTF #1
str_use:N l__almic_makestring_str
str_new:N #1 str_set_eq:NN #1 l__almic_makestring_str
ior_new:N g__almic_makestring_stream
str_new:N l__almic_makestring_str
seq_new:N l__almic_makestring_seq
cs_new_protected:Nn almic_makestring:n
% clear the auxiliary sequence
seq_clear:N l__almic_makestring_seq
% read the file and store the items
ior_open:Nn g__almic_makestring_stream #1
ior_str_map_inline:Nn g__almic_makestring_stream
seq_put_right:Nn l__almic_makestring_seq ##1
ior_close:N g__almic_makestring_stream
% remove the first item
seq_pop_left:NN l__almic_makestring_seq l_tmpa_tl
% remove the duplicates
seq_remove_duplicates:N l__almic_makestring_seq
%
str_set:Nx l__almic_makestring_str seq_use:Nn l__almic_makestring_seq
ExplSyntaxOff
begindocument
makestringjobname.dat
makestring[test]jobname.dat
textttmeaningtest
enddocument
add a comment |
With expl3
:
beginfilecontents*jobname.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandmakestringom
% #1 = macro to store the string in, #2 = file name
almic_makestring:n #2
IfNoValueTF #1
str_use:N l__almic_makestring_str
str_new:N #1 str_set_eq:NN #1 l__almic_makestring_str
ior_new:N g__almic_makestring_stream
str_new:N l__almic_makestring_str
seq_new:N l__almic_makestring_seq
cs_new_protected:Nn almic_makestring:n
% clear the auxiliary sequence
seq_clear:N l__almic_makestring_seq
% read the file and store the items
ior_open:Nn g__almic_makestring_stream #1
ior_str_map_inline:Nn g__almic_makestring_stream
seq_put_right:Nn l__almic_makestring_seq ##1
ior_close:N g__almic_makestring_stream
% remove the first item
seq_pop_left:NN l__almic_makestring_seq l_tmpa_tl
% remove the duplicates
seq_remove_duplicates:N l__almic_makestring_seq
%
str_set:Nx l__almic_makestring_str seq_use:Nn l__almic_makestring_seq
ExplSyntaxOff
begindocument
makestringjobname.dat
makestring[test]jobname.dat
textttmeaningtest
enddocument
With expl3
:
beginfilecontents*jobname.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandmakestringom
% #1 = macro to store the string in, #2 = file name
almic_makestring:n #2
IfNoValueTF #1
str_use:N l__almic_makestring_str
str_new:N #1 str_set_eq:NN #1 l__almic_makestring_str
ior_new:N g__almic_makestring_stream
str_new:N l__almic_makestring_str
seq_new:N l__almic_makestring_seq
cs_new_protected:Nn almic_makestring:n
% clear the auxiliary sequence
seq_clear:N l__almic_makestring_seq
% read the file and store the items
ior_open:Nn g__almic_makestring_stream #1
ior_str_map_inline:Nn g__almic_makestring_stream
seq_put_right:Nn l__almic_makestring_seq ##1
ior_close:N g__almic_makestring_stream
% remove the first item
seq_pop_left:NN l__almic_makestring_seq l_tmpa_tl
% remove the duplicates
seq_remove_duplicates:N l__almic_makestring_seq
%
str_set:Nx l__almic_makestring_str seq_use:Nn l__almic_makestring_seq
ExplSyntaxOff
begindocument
makestringjobname.dat
makestring[test]jobname.dat
textttmeaningtest
enddocument
answered 6 hours ago
egregegreg
739k8919393269
739k8919393269
add a comment |
add a comment |
To achieve this, you do not need anything beyond pgfplotstable.
documentclass[10pt,a4paper]article
usepackagepgfplotstable
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
ifnumk=0
xdefmyLstpgfplotsretval
xdefmystringpgfplotsretval
else
xdeftmpElOld0
edefnewelementpgfplotsretval
foreach oldelement in myLst
ifxnewelementoldelement
% typeoutduplicate
xdeftmpElOld1
fi
ifnumtmpElOld=0
xdefmyLstmyLst,pgfplotsretval
xdefmystringmystringpgfplotsretval
fi
fi
mystring
enddocument
add a comment |
To achieve this, you do not need anything beyond pgfplotstable.
documentclass[10pt,a4paper]article
usepackagepgfplotstable
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
ifnumk=0
xdefmyLstpgfplotsretval
xdefmystringpgfplotsretval
else
xdeftmpElOld0
edefnewelementpgfplotsretval
foreach oldelement in myLst
ifxnewelementoldelement
% typeoutduplicate
xdeftmpElOld1
fi
ifnumtmpElOld=0
xdefmyLstmyLst,pgfplotsretval
xdefmystringmystringpgfplotsretval
fi
fi
mystring
enddocument
add a comment |
To achieve this, you do not need anything beyond pgfplotstable.
documentclass[10pt,a4paper]article
usepackagepgfplotstable
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
ifnumk=0
xdefmyLstpgfplotsretval
xdefmystringpgfplotsretval
else
xdeftmpElOld0
edefnewelementpgfplotsretval
foreach oldelement in myLst
ifxnewelementoldelement
% typeoutduplicate
xdeftmpElOld1
fi
ifnumtmpElOld=0
xdefmyLstmyLst,pgfplotsretval
xdefmystringmystringpgfplotsretval
fi
fi
mystring
enddocument
To achieve this, you do not need anything beyond pgfplotstable.
documentclass[10pt,a4paper]article
usepackagepgfplotstable
beginfilecontents*attributetools.dat
Attribute
SL
SK
MC
SL
AA
PT
SK
UP
MC
endfilecontents*
begindocument
pgfplotstableread[columns=Attribute]attributetools.datdatatableA
pgfplotstablegetrowsofdatatableA
pgfmathtruncatemacroRowsInTablepgfplotsretval-1
foreach k in 0,...,RowsInTable
pgfplotstablegetelemkAttributeofdatatableA
ifnumk=0
xdefmyLstpgfplotsretval
xdefmystringpgfplotsretval
else
xdeftmpElOld0
edefnewelementpgfplotsretval
foreach oldelement in myLst
ifxnewelementoldelement
% typeoutduplicate
xdeftmpElOld1
fi
ifnumtmpElOld=0
xdefmyLstmyLst,pgfplotsretval
xdefmystringmystringpgfplotsretval
fi
fi
mystring
enddocument
answered 4 hours ago
marmotmarmot
124k6161304
124k6161304
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489369%2fappend-unique-characters-read-from-filecontents-to-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
foreach
executes the loop code inside two groups, so assignments have to either escape that group or be global. The way yourextendmystring
macro is designed you can prefix it withglobal
(ie,globalextendmystringtempstring
) and it will work.– Phelype Oleinik
7 hours ago
Thanks, it works :)
– Almic7
7 hours ago