Re: Formatting of strings
- From: GArlington <garlington@xxxxxxxxxxxxx>
- Date: Mon, 31 Mar 2008 07:22:04 -0700 (PDT)
On Mar 30, 8:53 pm, Ulf <ulf.he...@xxxxxxxxx> wrote:
I'm looking for the best way to combine two strings so that the result
ends with the 2:nd string in position 30-32. The 1:st string is 1 to
30 chars long.
Currently I use the following (untested) code.
char cc[] = new char[33];
for(int i = 0; i < 33; i++) { cc[i] = ' '; } //Make spaces
cc[30] = '/'; // This is the 3 chars for string2
cc[31] = '0';
cc[32] = '0';
string1.getChars(0,string1.length()- 1, cc, 0);
resultString = new String(cc);
I would appreciate suggestions both on the solution (perhaps this is
the best solution) and proper Java coding.
This operation will be used just a few times a day, so the solution
really doesn't matter for the project, but it matters for me trying to
learn Java.
/Ulf
How about a simple:
String temp = " "; // Set it to 30 spaces...
String resultString = (yourStr1 + temp).substring(0, 30) + yourStr2;
.
- References:
- Formatting of strings
- From: Ulf
- Formatting of strings
- Prev by Date: Re: More than 1 MouseListener
- Next by Date: Re: manupulating a xml-file
- Previous by thread: Re: Formatting of strings
- Next by thread: Re: Formatting of strings
- Index(es):