1
$\begingroup$

(Minimal example)

I'm dealing with the following array :

array = {
         {""},
         {"Analysis 1"},
         {"1 class TimeDependentAnalysis timeIntegrationScheme 1 solver 1 \*"},
         {"**"},
         {""}
        };

I export this array in a .txt file as the following :

Export["test2.txt", array, "Table"]

wich give me this nice result

enter image description here

now I have to insert some elements between the line "1 class TimeDependentAnalysis timeIntegrationScheme 1 solver 1 *" and "**", these elements are defined as

elements = Table[{StringForm["Text ``", i]}, {i, 1, 3}]

At the end I should get the following result :

enter image description here

NB : The file .txt will be used by an another program such that it can't be written differently

NB : The list "elements" can contain an infinite number of elements

Any ideas ?

$\endgroup$
2
$\begingroup$

I finally found a way to do it

addRow[a_, b_, n_] := Join[a[[;; n - 1]], b, a[[n ;;]]]
array = {
         {""}, 
         {"Analysis 1"}, 
         {"1 class TimeDependentAnalysis timeIntegrationScheme 1 solver 1 \*"}, 
         {"**"}, 
         {""}
        };
elements = Table[ToString@StringForm["Text ``", i], {i, 1, 3}];
output = addRow[array, elements, 4];
Export["test2.txt", output, "Table"]

However if there are another ways, I'm interesting !

$\endgroup$
1
  • $\begingroup$ Your original array is a list of lists. However, you insert "Texti" not as lists but as strings. Is this intentional or not? $\endgroup$ – Daniel Huber Jun 11 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.