Easiest way to create a string with n times character 'x'?
From: Arnold Peters (apet10_at_hotmail.com)
Date: 01/27/05
- Next message: Grant Wagner: "Re: Error 1311 when installing JDK 1.5"
- Previous message: hilz: "Re: objectA gives objectB to objectC"
- Next in thread: Heiner Kücker: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Heiner Kücker: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: mprudhom: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Joona I Palaste: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Rhino: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: anonymous: "Re: Easiest way to create a string with n times character 'x'?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Jan 2005 20:34:37 +0100
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
- Next message: Grant Wagner: "Re: Error 1311 when installing JDK 1.5"
- Previous message: hilz: "Re: objectA gives objectB to objectC"
- Next in thread: Heiner Kücker: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Heiner Kücker: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: mprudhom: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Joona I Palaste: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: Rhino: "Re: Easiest way to create a string with n times character 'x'?"
- Reply: anonymous: "Re: Easiest way to create a string with n times character 'x'?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|