aspose file tools*
The moose likes Beginning Java and the fly likes modify the arrray to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "modify the arrray to string" Watch "modify the arrray to string" New topic
Author

modify the arrray to string

Rajesh Veluchamy
Ranch Hand

Joined: Jan 15, 2008
Posts: 47
str[] array contains some data like str[]={"12","13","345"}

Now i want str1='12','13','345'
but i am getting a space between number and quotes(')
i.e,--> '12 ','13 ','345'

one more thing, i am not getting space in the last number(345)




[ March 13, 2008: Message edited by: Rajesh Veluchamy ]

-Rajesh.V<br /> Software Consultant
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

I don't know what you did because if I try your code I get '12','13','345' just as you want. I used your exact code with the addition of the declaration:

[ March 13, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Just wrote a quick test program, with your loop, and your test data. It ran fine. I'm not getting any extraneous spaces.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

As you're not adding spaces in yourself, they must be in the original data. You might try

str1=str1+",'"+str[ii].trim()+"'";


[Jess in Action][AskingGoodQuestions]
Neha Agarwal
Greenhorn

Joined: Mar 12, 2008
Posts: 16
public class Test {
public static void main(String[] args) {
String str[]={"12","13","345"};
StringBuffer str1 = new StringBuffer();
for (int ii = 0; ii < str.length; ii++)
{
if(ii==(str.length-1)) {
str1=str1.append("'"+str[ii]+"'");
}else{
str1=str1.append("'"+str[ii]+"',");
}

}
System.out.println(str1);
}

}
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Neha Java",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: modify the arrray to string