# Insert string elements to an array

(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

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 :

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 ?

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 !

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