Results 1 to 4 of 4
  1. #1
    mintu is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default Splitting paragraph into line statements

    Hello everyone,

    Being a beginner to JAVA, I am trying to find out a solution for splitting paragraphs in a file, into lines of statements.

    Eg:- Paragraph in the given text file "sample" is
    "Welcome to programming in JAVA. Java was developed by James Gosling. It is an object oriented language. "

    The desired output is
    Welcome to programming in JAVA
    Java was developed by James Gosling
    Java is an object oriented language

    Can anyone help me out to find the way of achieving this.

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

    Default

    One way or another, you're going to have to split String into 3 (or more) Strings. One way is to use the String#split(String regex) method, but do take care since it will fail if you try to use "." as the delimiter to split on. Since the parameter is a regex String, you'll have to "escape" the period with two backslashes.

    Another way is to search the String for the periods and then use this information to generate appropriate subStrings. Be sure to look at the String API regarding subStrings and how to generate them. Also look at the indexOf method.

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    449
    Rep Power
    6

    Default

    Fubarable said here a good idea.
    but i think as a beginner you cant understand about regular expression.Instead of that ,you may use Scanner for Read line from file.
    Mak
    (Living @ Virtual World)

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    use this:
    s.split("\\x2E");

    edit:
    or this to get rid of that extra space:
    s.split("\\x2E *"); <<-- there is a space there...
    Last edited by angryboy; 02-28-2009 at 08:44 AM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Array splitting
    By Lunarion in forum New To Java
    Replies: 3
    Last Post: 04-17-2009, 08:00 AM
  2. Splitting single string into array elements
    By phil128 in forum New To Java
    Replies: 11
    Last Post: 01-12-2009, 11:51 AM
  3. How to obtain Paragraph Layout
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 10:36 AM
  4. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM
  5. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 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
  •