• Post Reply Bookmark Topic Watch Topic
  • New Topic

newline Split in java  RSS feed

 
Chandra shekar M
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have this line u:http://www.armaniexchange.com/\nlast_edit_time:1151018232\nnewcat:Shopping/Clothing\nuksite:0\ntype:\nlast_edit:artisands\nd:Giorgio Armani's collection offers seasonal fashion items for men and women.\nt:Armani Exchange\n in a file. I do a read line and split it based on the s
split("\\n") or split("\n") or split("\\u000A") it doesnt WORK and returns same line.

Instead of reading from the file if i copy paste this line directly in code as a value to some variable say
String s="u:http://www.armaniexchange.com/\nlast_edit_time:1151018232\nnewcat:Shopping/Clothing\nuksite:0\ntype:\nlast_edit:artisands\nd:Giorgio Armani's "
and make call to any one of them then it Works Fine but when i read the same line from the File assign to some String varible and use any of the above it is not splitting.

where is the mistake here. by the way i'll be running this code on Linux machine.

Thanks


 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you read the file, what readers do you use? BufferedReaders readLine() returns a line without the new line character. Could you please post some code?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this related to SCJP or is this a requirement / assignment of some sort ?
 
Chandra shekar M
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already completed SCJP, This is some thing m trying for myself. Well To read a file m reading the using


I know m doing readline but the data is abcd:efgh\nijk:lmn... you can see the data that got returned from readline() which m trying to split.

Thanks



 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need double escaping, once for Java and once for regex, try using "\\\\n".
 
Chandra shekar M
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all, \\\\n solution worked.

Thanks
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're Welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!