File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String manipulation" Watch "String manipulation" New topic
Author

String manipulation

Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi All,

Currently I am trying to do a string manipulation where in a for loop I want to append new pieces of String in front of and at the end of the existing string.
So the output should be something like this.

I have a String array = {"False","No","Yes", "True};

So all the initial values should appear twice like shown below & the last value should be shown only once.
-----------------------------------------
False No Yes True Yes No False
-----------------------------------------

Do let me know how to go about the same

Bye,
Uday
Venkata Narayana Reddy Pingala
Greenhorn

Joined: Jan 16, 2007
Posts: 3
Hi,

Check this code. it will give you waht do you want:::

String array[] = {"False","No","Yes", "True"};
String afterApp="";
int i;
for(i=0;i<array.length;i++){
afterApp+=array[i]+" ";
}
for(i=i-2;i>=0;i--){
afterApp+=array[i]+" ";
}
System.out.println("After Append "+afterApp);


Regards,
Venkat
Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Check out the StringBuilder class, added in Java 5. It is basically a mutable String class, and allows you to avoid iterate twice through the array.
[ January 16, 2007: Message edited by: �dne Brunborg ]

Entia non sunt multiplicanda praeter necessitatem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String manipulation
 
Similar Threads
Compatibility issues with my applet and label color.
RHE Qs
LinkedHashSet subset of HashSet ?? (K&B bk shows otherwise)
Precedence
Intercepting XML using Servlet Filter