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

    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.


  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power


    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, 01: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, 06:26 PM
  4. using Delimiter with metacharacters
    By wntdaliv in forum New To Java
    Replies: 10
    Last Post: 12-02-2008, 07:42 AM
  5. delimiter
    By satin in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 11: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