Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to split the new line character("\n") in string in JAVA

Posted on 2004-11-01
6
Medium Priority
?
3,719 Views
Last Modified: 2012-05-05
Hi,

   I have a string where there is a new line character ("\n") and i want to split the new line character .
Example of string :
   afasdfasdf
sfasdfasdffgsdgsg
dfhdgg
ghjh

After splitint the above string with str.split("\n");
i'm not able to get the splited part of the string pls suggest me how to split a string according to new line character

Thanx
0
Comment
Question by:mohan21_kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
Murugesan Nagarajan earned 80 total points
ID: 12470288
public class Dinesh_P_V
{
      public static void main(String ars[])
      {
            String s="Dinesh\n_\nP\n_\nV";
            System.out.println("Before Split:");
            System.out.println(s);
            String arr[]=s.split("\n");
            System.out.println("After Split:");
            for(int i=0;i<arr.length;i++)
            System.out.println(arr[i]);
      }
}

HTH
0
 

Expert Comment

by:mohankumarbangalore
ID: 12470344
the above code works but i want to check it for the file and split the file into no of files according to tne paragraph
0
 
LVL 9

Expert Comment

by:Murugesan Nagarajan
ID: 12470437
http://www.javacoffeebreak.com/java103/java103.html

Here you can have a view on file handling in java.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question