Results 1 to 2 of 2
  1. #1
    adityasirohi is offline Member
    Join Date
    Feb 2010
    Posts
    4
    Rep Power
    0

    Default How to use delimiter in java

    Hello Friends,

    I want to use some demiliter functionality in a class i am writing. I have a path: /net/lock/vol/netsys/homes/asirohi/spins/7.1a/XN/server_install.xml, i want to delimit this String by "/" and get the 1st field and the last field. So the output should be: net server_install.xml..

    How do i go about, i need ideas or some example program.

    Thanks
    Aditya

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Use String.split. It will return an array containing each token. Then you take the first and last elements from the array.

    Or you could create your own simple routine using methods from the String class. You use the indexOf() method to find the first occurrence of the delimiter and then substring(...) out the text. Then you use the lastIndexOf() method to find the last delimeter and substring out the last token.

    Either way you can start by reading the String API for methods to help you.

Similar Threads

  1. How do you Use Backslash as a Delimiter?
    By Mobius-1 in forum New To Java
    Replies: 3
    Last Post: 12-14-2009, 12:39 AM
  2. Delimiter question
    By Kangaroo128 in forum New To Java
    Replies: 10
    Last Post: 09-09-2009, 09:28 AM
  3. Use of Scanner class and Delimiter
    By tjhodge in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 05:26 PM
  4. using Delimiter with metacharacters
    By wntdaliv in forum New To Java
    Replies: 10
    Last Post: 12-02-2008, 06:42 AM
  5. delimiter
    By satin in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 10:50 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
  •