1

This is a single field value and has to be split based on blank lines.

Eg:

abc street 
xyz 
city 785263 

lmn street 
abc 
city 462738 

I tried AddressList = addresses.split('\n{2}') but dose not work.

  • Use addresses.split('\\s'). – arut Sep 28 at 4:31
  • @arut blank lines, not just blanks? – sfdcfox Sep 28 at 4:37
  • @sfdcfox My bad [+1 to your ans]. I ran only by the title before commenting. – arut Sep 28 at 4:44
3

addresses.split('\n{2}') only works if it's actually just newlines (\n). There are three common newline connections, LF (\n), CR (\r), and CRLF (\r\n).

To be compatible with all of these, try:

addresses.split('(?m)\\s*^\\s*$\\s*')

This has several parts:

(?m) multiline mode enabled
\\s* zero or more whitespace
^ Beginning of a line (multiline mode)
$ End of a line (multiline mode)

So: "In multiline mode, find any spaces followed by any start of line, with any spaces, then an end of line, followed by any more spaces."

Or, you could replace CRLF and Cr to just LF, then your original code should work:

addresses.replaceAll('(\\r\\n|\\r)','\n').split('\n{2}')
| improve this answer | |
  • addresses.replaceAll('(\\r\\n|\\r)','\n').split('\n{2}') Thanks, it worked. – user70573 Sep 28 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.