• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

modify the arrray to string

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wrote a quick test program, with your loop, and your test data. It ran fine. I'm not getting any extraneous spaces.

Henry
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you're not adding spaces in yourself, they must be in the original data. You might try

str1=str1+",'"+str[ii].trim()+"'";
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}

}
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Neha Java",
Please check your private messages.
-Ben
reply
    Bookmark Topic Watch Topic
  • New Topic