divide id numbers with comma


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: divide id numbers with comma

  1. #1
    Join Date
    Jan 2009
    Posts
    1

    divide id numbers with comma

    hi everybody,

    As iam new to forum site and this is my first post,i may make a mistake of how to interact with other persons

    kindly forgive me.


    my problem is:

    i want to get strings attach with comma

    if i do like following ,at the end iam getting comma which should be removed
    string str=str+",";

    kindly solve my problem.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Welcome to DevX

    I am unclear on what your goal is here.

    One one hand you say
    Quote Originally Posted by zahurjava
    I want to get strings attach with comma
    , but then you say
    Quote Originally Posted by zahurjava
    if i do like following, at the end iam getting comma which should be removed.
    Could provide an example of what you trying to achieve?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    By the topic of your post, I think you have several strings you want to append coma to, but there should be no coma. Eg: one,two,three,four

    Is that right? If it is, here are two approaches you can follow:
    1)

    Code:
    // Add each of the string as an array item
    var strs = [], len=0;
    
    strs[len++] = item1;
    strs[len++] = item2;
    .
    .
    .
    
    var finalstr = strs.join();

    2)
    Code:
    function myappend(str, item)
    { return str ? str+","+item : item; }
    
    var mystr;
    mystr=myappend(mystr, item1);
    mystr=myappend(mystr, item2);
    .
    .
    .
    Or if its in a loop, something like this:
    Code:
    var mystr="";
    if(data.hasMore())
      mystr=data.next();
    while(data.hasMore())
      mystr += "," + data.next();

  4. #4
    Join Date
    Jan 2009
    Posts
    11
    I think he meant Java code:

    Code:
    String[] s = { "a", "b", "c", "d" };
    String s2 = s[0];
    for (int i = 1; i < s.length; i++) {
        s2 += ", " + s[i];
    }
    System.out.println(s2);

Similar Threads

  1. Replies: 3
    Last Post: 08-21-2008, 08:18 AM
  2. Help with Rational Numbers (C++)
    By cloudjc in forum C++
    Replies: 1
    Last Post: 04-28-2008, 12:26 PM
  3. Replies: 1
    Last Post: 05-31-2006, 02:14 AM
  4. ID Numbers are out of sequence
    By sensei in forum VB Classic
    Replies: 1
    Last Post: 05-18-2006, 01:25 PM
  5. Replies: 8
    Last Post: 10-15-2005, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center