01-25-2016 06:13 AM
The following behavior is quite strange.
I hope some one has an explanation...
The following sequence leads to a strange error (116 - Unflatten From String)
1. I create a cluster that contains a string and an array of numbers
2. The string length is EXACTLY 13 characters. (no more no less)
3. I flatten the cluster to a string
4. I save the string to a file
5. I read the file
6. When I try to convert the string back to the cluster - I get an Error.
I have investigated a bit - and I get the same error with string length of 269, 525 and 781.
What is going on???
01-25-2016 06:37 AM - edited 01-25-2016 06:41 AM
I didn't run the code, but I can see that your string lengths are all multiples of 256+13. When you flatten a string, its length is encoded as part of the flattened data, so that whatever unflattens it knows how many bytes to look at. Most likely, the issue is that the byte equal to 13 is interpeted as a carriage return character somewhere (since that's the ASCII value). My bet would be the file functions (which you can see from their icons are configured to look at line breaks). I woudn't be surprised if the same thing happens with strings of length 10 (which is the line feed character), although I'm guessing your test would have found that, so it probably doesn't happen.
You will probably see the difference clearly if you compare the string saved to file with the string read from the file and presumably the easiest solution is to configure the write and read to ignore line breaks.
01-25-2016 06:52 AM
Thanks!
I have replaced the "Read from text file" to "read from binary file" and set the data type string and it works flawlessly.
After finding out the reason it looks so trivial...
01-25-2016 06:54 AM
01-25-2016 06:54 AM
01-25-2016 02:11 PM
@Hazkel wrote:
You can actually make this even simpler by not using the Flatten To String and the Unflatten From String. Just use the cluster for a direct write/read with the Write To Binary File and Read From Binary File.