Results 1 to 12 of 12
  1. #1
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default How to access element in a CSV?

    Actually i have table in access with two columns, as follows.

    TID Items
    1 1,3,9,13,23,25,34,36,38,40,52,54,59,63,67,76,85,86 ,90,93,98,107,113

    like above with many rows.

    How can I access the items one by one?

    Actually I wanted to count the number of occurence of each item in the database and update in a new table.

    I know upto fetching this rows from the table, but how to do the rest i have no idea.

    Can anyone give some idea?

    thanks in advance.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,560
    Rep Power
    25

    Default

    If this were a java programming question, you could StringTokenizer with a delimiter of , then iterate thru nextToken()s

  3. #3
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default

    ya it certainly is a Java Programming question....
    and thanks for the reply, i will try and let u know.....

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Or perhaps even better then tokenizer which Sun appears to be trying to get us away from, try to use the String#split method:
    Java Code:
    String[] tokens = myString.split(",");

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Yes, split is the new preferred way.

  6. #6
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default

    I dont know whether I am permitted to ask for an example code, since I am newbie, I would be better off with an example code, you may give that, only incase you have the code at your easy reach.
    Otherwise its fine.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I dont know whether I am permitted to ask for an example code, since I am newbie, I would be better off with an example code,
    The truth is quite the opposite actually. You'll be much better off without sample code since real learning is best stimulated by having to struggle a bit to come up with and test a solution on your own.

    Good luck.

  8. #8
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default

    ok here is wat a want to do now

    i have

    str="2,3,10,15,23,26,34,36,39,42,52,55,59,63,67,76 ,85,86,90,93,98,107,114";

    how will i fetch the item one by one,

    am i permitted to ask that ?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Look up String#split() as suggested above and as noted above it will give you an array of String. I recommend that you try it out, that you print out the resulting array, and that you see for yourself what happens. Good luck.

    BTW, here's the String#split() api: String (Java Platform SE 6). Have a look, then give it a try. Feel free to come back with your code if it doesn't work as you expect it to.
    Last edited by Fubarable; 08-17-2008 at 10:42 AM.

  10. #10
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default

    @Fubarable

    Here is my code, and it works fine.

    public class StringSplit {
    public static void main(String args[]) throws Exception{
    new StringSplit().doit();
    }

    public void doit() {
    String s3 = "2,3,10,15,23,26,34,36,39,42,52,55,59,63,67,76 ,85,86,90,93,98,107,114";
    String [] temp = null;
    temp = s3.split(",");
    dump(temp);
    }

    public void dump(String []s) {
    System.out.println("------------");
    for (int i = 0 ; i < s.length ; i++) {
    System.out.println(s[i]);
    }
    System.out.println("------------");
    }
    }

    And you know what? I got this code after googling with your recommend term String split usage.

    Now my requirement is met.

    Thanks a ton for your reply.

    I owe you one :)

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Just curious what's your ultimate goal here: is it to just sneak by in class with a decent passing grade and then saying goodbye to programming forever as a career or even avocation, or is it to truly study, learn and love the beauty of programming, to appreciate the artistic and creative process that both come into play when composing a program, to feel the sense of joy when multiple complex components are finally added together run just as they're supposed to, where you see how they click together oh so nicely, like hand and glove, and work together as one...? I can go on.

    I guess you can tell, I do this for love, not for money, that I'm not nor will I ever be a professional programmer. Programming and music are my two biggest hobbies, and you know the feeling I get from composing a new piece of music is the same that I get for creating a beautiful program.

    If you want to the same, please take my advice and experiment with your code. Run it up, down, left, right, inside the box, outside the box or the frackin' universe. Chop it, mix it, change it, add lines just for the heck of it to "see what will this do..."

    But don't download code just to satisfy an assignment. You're cheating yourself if you do. The creating is the hardest part but also the most satisfying part. Stick with this long enough and you'll see. Good luck.

    and sorry for the strange digression.

  12. #12
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Posts
    16
    Rep Power
    0

    Default

    @Fubarable

    No one Can deny one single point that you told above.

    But right now, I should complete a project for which I needed some code that is easy to understand and use.

    However, I am in the process of learning the beautiful programming language, devoting my whole time to which will land me into a stage where I cannot complete my project.Also FYI I am planning to write certification by Jan, for which I very well know my method won't work, and only your method works.

Similar Threads

  1. how can we get the element of by using the hashtable
    By raj reddy in forum Web Frameworks
    Replies: 1
    Last Post: 05-06-2008, 01:45 PM
  2. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 05:26 PM
  3. a no such element exception
    By headlice1 in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:36 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:51 AM
  5. Replies: 4
    Last Post: 07-31-2007, 05:19 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
  •