Re: Formatting of strings
- From: Mark Space <markspace@xxxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 20:01:45 GMT
Ulf 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.
This looks ok (I didn't try to compile it however). You should give it a go. It might even be the most efficient way of doing it.
However, from a learning Java standpoint, you should look at StringBuffer and StringBuilder classes. Those are the more normal ways of making strings by building up parts at a time.
.
- References:
- Formatting of strings
- From: Ulf
- Formatting of strings
- Prev by Date: "PriorityMap"
- Next by Date: Re: need class methods/variables to represent the execution of an application
- Previous by thread: Formatting of strings
- Next by thread: Re: Formatting of strings
- Index(es):
Relevant Pages
|