A
Arnold Peters
Assume I want to create a string of length n which contains n times the character 'x'.
How do I implement this the easiest way? n could vary from function time to time.
Ok. I could code
char mychar = 'x';
String tmp = "";
for (int i=1; i<n; i++)
tmp = tmp + String(mychar);
But this is very (!) inefficient.
Other solution would be:
String ressource = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String tmp = ressource.subsctring(0,n);
But this is inefficient too and requires a a priori determination of the maximum possible
length;
As far as I know there is a function similar to
String tmp = makeString('x',n);
but I don't remember the exact name.
Can somehelp give me a hint?
Arni
How do I implement this the easiest way? n could vary from function time to time.
Ok. I could code
char mychar = 'x';
String tmp = "";
for (int i=1; i<n; i++)
tmp = tmp + String(mychar);
But this is very (!) inefficient.
Other solution would be:
String ressource = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String tmp = ressource.subsctring(0,n);
But this is inefficient too and requires a a priori determination of the maximum possible
length;
As far as I know there is a function similar to
String tmp = makeString('x',n);
but I don't remember the exact name.
Can somehelp give me a hint?
Arni