Results 1 to 4 of 4
- 02-27-2009, 02:14 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
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.
-
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, 07: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, 08:41 AM #4
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
-
Array splitting
By Lunarion in forum New To JavaReplies: 3Last Post: 04-17-2009, 08:00 AM -
Splitting single string into array elements
By phil128 in forum New To JavaReplies: 11Last Post: 01-12-2009, 11:51 AM -
How to obtain Paragraph Layout
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:36 AM -
splitting string and replacing
By itsme in forum New To JavaReplies: 1Last Post: 12-11-2007, 03:08 PM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks