Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting by enter

 
Carlos Valderrama
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I hope you're all ok!

In my last post and thanks to your help I managed to split the text from a text area into lines and add a "\n" and the end of each line. After that I succesfully updated the field in the database.

So technically the text in the field has been updated to: line1"\n"line2"\n"line3"\n"line4 ( eventhough I don't get to see the "\n" character, I know that it has worked because when I copy-paste the field

directly from the database into a text editor it respects the "\n".


Well, now when I read the string from database and try to apply any of the following methods to the String:

myString.split("\n") , myString.split("\\n") , myString.split("\n\r"), myString.split("[\r\n] "), myString.split("[\r\n] "), myString.split("\\r?\\n"), myString.split(System.getProperty("line.separator"))

none of them has worked

So again I would really appreciate any comment or suggestion to try!

Thanks in advance !!











 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is usually an escaping problem. The characters you need to escape have to go through two levels of escape: first one for the Java String, and a second for the RegeEx. So try string.split("\\\\n") but maybe string.split("[\\n]") would work as well. How exactly do you add the characters to the string? And how do you know it is or is not working?
 
Carlos Valderrama
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve thank you for replying me!

Look, a field value from the database looks like this:

Before

AV CONSTITUCION RES LOS MANGOS TORRE F PISO 14 TORRE 145F


After:


Adding at the end of each splitted line with line+"\n";
AV CONSTITUCION RES LOS MANGOS

TORRE F PISO 14 TORRE 145F

It actually is stored like this in the database.

And i know it works because I copy-paste the field in a text editor and the "\n" are respected.

My question is

why can't i get to split it into an array of splitted parts?


I'm using

String[] ArrayParts = dirOrd.split("[\\n]"); ( with any of the other it doesn't works either)

I'm guessing it could have something to do with the library to retrieve values from the database? sqljdbc4.jar?



 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:How exactly do you add the characters to the string? And how do you know it is or is not working?


These questions still remain unanswered.

Add to that, what does the string look like when you get it from the DB using your library before you process it?

I believe the "\n" is there, but how - specifically - showing code - do you add it? And how do you know it is not splitting? You show that you do the split. And you say that it does not work. But what does it do, how do you know what it is doing, and how do you prove it is or is not working the way you expect it?
 
Carlos Valderrama
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,

Some replacements where applyed to the string after I retrieved it from database.. including one [\\n\\t]

I'm really ashamed with you, because I took part of your time when i simply needed to debug it more carefully.

Thanks for you support.

I apologize



 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No reason to feel ashamed, we all need help, and the forums are a great place to get it. I just hope something I said was helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic