1
$\begingroup$

How do I generate the sequency {disp1, disp2, disp3, ...}?

I tried the following but it didn't give me what I expected:

List1=Table[JoinString["disp","i"],{i,1,5}]

This gives the list {dispi,dispi,dispi,dispi,dispi}

Any help is appreciated.

Thanks

$\endgroup$
2
  • $\begingroup$ You need to use ToString[i] in Table otherwise you'll get what you say, i.e. "i" literally. $\endgroup$ Commented Oct 21, 2014 at 14:55
  • $\begingroup$ Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basics of the site. Your question may be put on-hold because it seems to be a duplicate. Read the links to understand what this is about. If you think that would be a mistake, please edit your question to improve it and make it more specific. $\endgroup$
    – rhermans
    Commented Oct 21, 2014 at 15:02

2 Answers 2

1
$\begingroup$

use StringJoin instead of JoinString and ToString

list1 = Table[StringJoin["disp", ToString[i]], {i, 1, 5}]
{"disp1", "disp2", "disp3", "disp4", "disp5"}
$\endgroup$
1
  • $\begingroup$ Thank you...I should have thought about that. $\endgroup$
    – user13600
    Commented Oct 21, 2014 at 14:59
1
$\begingroup$

Alternative:

Range[5] /. n_Integer :> StringJoin[{"disp", ToString@n}]
$\endgroup$

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