Results 1 to 4 of 4
- 02-27-2009, 03:14 PM #1Member
- Join Date
- Feb 2009
- Rep Power
Splitting paragraph into line statements
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.
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.
- 02-28-2009, 08:55 AM #3
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)
- 02-28-2009, 09:41 AM #4
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 09:44 AM.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- By Lunarion in forum New To JavaReplies: 3Last Post: 04-17-2009, 09:00 AM
- By phil128 in forum New To JavaReplies: 11Last Post: 01-12-2009, 12:51 PM
- By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 11:36 AM
- By itsme in forum New To JavaReplies: 1Last Post: 12-11-2007, 04:08 PM
- By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 01:19 AM