...

Java

Aonlan
03-14-2005, 05:01 AM
i have a code:

System.out.print(strWord.substring(0,1));
for (intCounter = 1; intCounter <= intStringLength-1; intCounter++){

intCounter2 = intCounter + 1;
strSubFinalWord = strWord.substring(intCounter,intCounter2);
strFinalWord = "-" + strSubFinalWord;

System.out.print(strFinalWord);
}
System.out.println("");
is it possible to not do a lot of system.out.println and system.out.print n make a string that would equal to the final product of the above

Unit
03-15-2005, 07:01 PM
sure..

strWordOutput = strWord.substring(0,1);
for (intCounter = 1; intCounter <= intStringLength-1; intCounter++){
intCounter2 = intCounter + 1;
strSubFinalWord = strWord.substring(intCounter,intCounter2);
strWordOutput = strWordOutput + "-" + strSubFinalWord;
}

There might be a better way to do this. The word you want is in strWordOutput.

smeagol
03-15-2005, 11:42 PM
You could also use a StringBuffer in java.util:


StringBuffer buffer = new StringBuffer();

buffer.append(strWord.substring(0,1));

for (intCounter = 1; intCounter <= intStringLength-1; intCounter++)
{
intCounter2 = intCounter + 1;
buffer.append("-" + strWord.substring(intCounter,intCounter2));

System.out.print(buffer.toString());
}

hinokata
03-23-2005, 07:18 AM
NIO's CharBuffer would work in the case as well.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum