?
Solved

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

Posted on 2004-11-01
6
Medium Priority
?
3,726 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
  • 2
3 Comments
 
LVL 10

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 10

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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

600 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