concatenation of text

HenkH shared this question 10 years ago
Answered

A list contains letters, for example, mylist={{"b","i","n"},{"b","a","l","k"}}.

These lists are created somewhere and might contain ay number of sublists with any number of letters.

I would like to concatenate all letters/elements of a list into a single Textobject.

for example "bil" and "balk".

What command should I use?


Kind regards

Henk Hietbrink

Comments (5)

photo
1

Hi,

Try

    Sequence[Sum[Element[mylist, i]], i, 1, Length[mylist]]

M_OLoughlin

photo
1

Hi,


Zip[Sum[A],A,mylist] is simpler in this case. But neither really work as they produce superimposed text.


Another possibility is to use the spreadsheet to create individual texts for each element of your list.

Use FillCells[A1,mylist] this will create a row with each element in a separate cell.

Set A2=Sum[A1] and copy across.


Simon

photo
1

Maybe this can help (works only if your main lists elements are lists of string elements, but not lists like in mylist={{"b",{"1","2"}, "n"},{"b","a","l","k"}}):


mylist={{"b","i","n"},{"b","a","l","k"}}

mylist2=Join[mylist]

mytext=Sum[mylist2]


Cheers, Carlos

photo
1

Hi,


Following slik's suggestion of using Zip, here is an updated version:

    list1 = Zip[Sum[A], A, mylist]

    list2 = Sequence[Insert[", ", list1, 2i], i, 1, Length[list1] - 1]

    list3 = Zip[Sum[A], A, list2]

    mytext = Sum[list3]

Hide all the lists


M_OLoughlin

photo
1

Another way without using Zip:


    mytext=Sum[Join[Sequence[Append[Element[mylist,i]," "],i, 1,Length[mylist]]]]

© 2022 International GeoGebra Institute