I am very new to JScript, and windows scripting in general, and I have some data which I have read from a file and converted to a string, I want to split this data into two data arrays so they can be used separately. The data looks like this when I output from the file, showing the two parts which are deliminated by a newline character. If I split the data using (" ") it correctly separates each number, however I want to do this after separating the two sets of data first.
5.000000 9.000000 3.000000 7.000000 1.000000 4.000000 6.000000 2.000000 8.000000 0.000000
2464.000000 2464.000000 616.000000 2464.000000 154.000000 1232.000000 2464.000000 308.000000 2464.000000 77.000000
When I run code to split the two parts I receive this result
res 0 = 5.000000 9.000000 3.000000 7.000000 1.000000 4.000000 6.000000 2.000000 8.000000 0.000000 ,2464.000000 2464.000000 616.000000 2464.000000 154.000000 1232.000000 2464.000000 308.000000 2464.000000 77.000000
res 1 = undefined
This is the code I used to generate the above outputs
//Outputs 1
for( let i=0; i<data.length; i++) {
println(data[i]);
}
data = data + ''; //Convert Data from object to String
var res = data.split("\n")
//Outputs 2
console.log("res 0 = " + res[0]);
console.log("res 1 = " + res[1]);
This is the result I want
res 0 = 5.000000 9.000000 3.000000 7.000000 1.000000 4.000000 6.000000 2.000000 8.000000 0.000000
res 1 = 2464.000000 2464.000000 616.000000 2464.000000 154.000000 1232.000000 2464.000000 308.000000 2464.000000 77.000000
Edit: Code that reads the data
function dataRead(fname) {
console.log("Reading sequence...");
var fs = WScript.CreateObject("Scripting.FileSystemObject");
var lines = [];
var stream = fs.OpenTextFile(fname);
while(!stream.AtEndOfStream) {
lines.push(stream.ReadLine());
}
stream.Close();
return lines;
}
Edit: Matlab Code that writes the data
data = [T.seq; T.duration_bits];
newfile = [dir '\' name '.txt']
fp = fopen(newfile, 'w');
fprintf(fp,'%f ', data(1,:));
fprintf(fp,'\n');
fprintf(fp,'%f ', data(2,:));
fclose(fp);
(object to string was from What is causing the error `string.split is not a function`?)