I currently have an array containing x amount of strings and am looking to append all of these entries to a string in OCaml.
I know that the way to append a string to another in OCaml is by using
let a ="Hello"
let b= "Blah Blah " ^ a
However I would like to do this using all entries in my array. Then continue the string after appending the full array. Something similar to this:
let myArray = Array.make stages "Some text"
let myString = "I'm looking to append "^(ALL ENTRIES IN ARRAY)^" to this string"
If you had a list of strings rather than array then String.concat will do the trick. So if you have array you could convert the array to list and then apply String.concat as in:
String.concat " " (Array.to_list str_arr)
But if you don't want to convert it to a list you could use fold_left as in:
Array.fold_left (fun x y -> x ^ y ^ " ") "" str_arr
Notice that fold_left appends a space to every string in the array including the last one. String.concat is better; it uses the filler only between the strings