Help me to Substring pls!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Help me to Substring pls!!

  1. #1
    Join Date
    Mar 2006
    Posts
    7

    Help me to Substring pls!!

    Hi all,

    I hv a problem about substring method, I want to seperate data that I hv already got from db. An example of data as below message.

    Data:
    pic1.jpg,read1.pdf,abc.jpg,you_to_me.txt,

    After I received data from db, I would like to delimited each file name by "," (comma) then displays as the below expected result

    Expected result:
    tmp1 = pic.jpg
    tmp2= read.pdf
    tmp3 = abc.jpg
    tmp4= you_to_me.txt

    Pls kindly help me. thank you very much

  2. #2
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    your using the wrong method. Use the split method.

    example:

    String[] splitData;
    String data = "data1,data2,data3,data4";

    splitData = data.split(",");

    create an array variable that will hold the deliminated data. Then when u need the data you simply use it like this.

    for (int i=0; i <= splitData.lenght;i++)
    {
    System.out.println(splitData[i]);
    }

    Hope that helps.

  3. #3
    Join Date
    Mar 2006
    Posts
    7
    Thank you very much "Major" but I hv another problem, I cannot this method because there is a variable of data. I mean simetime my data has 4 filenames somtime 10 or more, it is not stable if I use String array I will seperate only 4 filenames....
    can i specific size of array?

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The Scanner class will create an array of all of the tokens - dynamically, as many elements as there are tokens. I believe that split() will do the same.

  5. #5
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    hi pearwarin, u dont need to set how many array u need in advance, u just decalre an instance of an array variable and not set it size, the split method will then allocate the size. The scanner class is also an option as mentioned by nspils, but it is available for java 5 i believe.

  6. #6
    Join Date
    Mar 2006
    Posts
    7
    Ok I got it ! Thank you very much

Similar Threads

  1. thread problem....pls help
    By Satish in forum Java
    Replies: 0
    Last Post: 11-29-2001, 10:07 AM
  2. class path problems pls help
    By sunil in forum Java
    Replies: 1
    Last Post: 06-13-2001, 10:03 AM
  3. Replies: 0
    Last Post: 11-22-2000, 04:42 PM
  4. PLS CHECK THE CODE
    By SATISH in forum Java
    Replies: 1
    Last Post: 08-30-2000, 01:37 PM
  5. Replies: 1
    Last Post: 08-20-2000, 02:53 PM

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