Sidebar

How can I process and split a text file, regardless of source system line encoding?

+1 vote
569 views
asked Nov 6, 2013 by matt-w-2627 (3,220 points)
How can I be sure that QIE will handle the endofline / newline / carriage return within the text file I am processing into an Array, regardless of source system (Unix, vs Windows, etc)?

1 Answer

+1 vote
 
Best answer

when processing the text file, it is best to use a regular expression to handle the line encoding.

reference for regular expressions in javascript: http://www.javascripter.net/faq/regularexpressionsyntax.htm

for example:

var SourceArray = source.getNode('/').split("\\r?\\n|\\r");

the above code will handle situations where the carriage return is present along with the newline, if newline is by itself, or if the carriage return is by itself.

Historically, MacOS's line encoding is \r, Windows is \r\n and Unix is \n

You can test the use cases by changing the line encoding in your sample messages,

Hex 0A = Newline (\n)
Hex 0D = Carriage Return (\r)

answered Nov 6, 2013 by matt-w-2627 (3,220 points)
edited Nov 6, 2013 by matt-w-2627
...