This prints "1000 elements" and "1000 strings" as expected.

1
2
3
4
5
let astr = "ABCDEFGHIJK This is string number:" 
let arr = [| for i in 1..1000-> astr + i.ToString("d5")  |]
let cat = concatenate_all arr
arr.Length |> printf "%d elements\n"
cat.Length / (astr.Length + 5)|> printf "%d strings\n"

It would be very bad indeed if this didn't work - can you post code that repro's the problem?

Do you have some multi-threading interaction or other issue?

By on 11/10/2009 10:53 AM ()

I figured out the problem!

Sorry I've mistaken, the problem is not in concatenation, the problem is in StreamWriter. Your example works fine, but when I add

1
2
3
4
let sw = new StreamWriter("SomeFile.txt")
for line in strArr do
    sw.WriteLine(line)
sw.Close

Stream doesn't close (should have written 'sw.Close()' instead of 'sw.Close') and part of string remains in sw buffer not written to a disk.

By the way, why doesn't compiler throw some warning or exception on line 'sw.Close' and instead seems to simply ignoring it?

By on 11/10/2009 1:04 PM ()

> By the way, why doesn't compiler throw some warning or exception on line 'sw.Close' and instead seems to simply ignoring it?

Actually it should output warning that result must be of type unit. Maybe you missed this.

By on 11/12/2009 10:31 AM ()

If I type this into the interactive, it works fine:

1
2
3
4
5
6
let sw = new System.IO.StreamWriter("c:\\temp\\SomeFile.txt") 

for line in arr do 
    sw.WriteLine(line) 

sw.Close() ;;

(I assume you meant "sw" and not "fs", and "line" and not "arr"

BTW - try posting real code from a file or FSI instead of typing pseudocode...

By on 11/10/2009 4:33 PM ()

Weird.

Anyway, you should replace your:

1
let sw = new StreamWriter("SomeFile.txt") 

with

1
use sw = new StreamWriter("SomeFile.txt") 

So that things get cleaned up in case something bad happens in your loop. You can try adding an

fs.Flush()

before the close - but it shound't be necessary.

By on 11/10/2009 4:24 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper