• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

modify the arrray to string

 
Rajesh Veluchamy
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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 ]
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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 ]
 
Henry Wong
author
Marshal
Pie
Posts: 21423
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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()+"'";
 
Neha Agarwal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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);
}

}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic