I am trying to construct this string for printing one message.
"At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(',');
from watch is VsCode:
where index =0;_subIndex =0;telNum.TelephoneDeviceType =Mobile;telephoneEnum=["Mobile","Landline"];
It's returning :
At position #[0][0] TLPHN_DVC_TYP NaN ,allowed Mobile,Landline
Full Code:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) > 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
the condition should not satisfy but not sure why it's going inside the if and NaN returning. any suggestion?
It's the two plus signs: "] TLPHN_DVC_TYP " + + _telNum?// ...etc. The second one is parsed as the unary +, or a conversion to number, which obviously fails. Compare:
console.log("foo" + "bar");
console.log("foo" + + "bar");
Added #1:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) >= 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +_telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
I am working on an HTTP fileserver and stumbled upon a problem with fs.readFileSync(). However, the function adds + signs which prohibits me from writing the value to another value.
(This is just to show what happens and does not represent the full functionality of the intended code)
samplejs.js
var content = fs.readFileSync("D:/sampleproj/example.txt", {encoding:"utf8"});
console.log(content);
output:
"\t'#0000CC',\r" +
"\n\t'#0000FF',\r" +
"\n\t'#0033CC',\r" +
"\n\t'#0033FF',\r" +
"\n\t'#0066CC',\r" +
"\n\t'#0066FF',\r" +
"\n\t'#0099CC',\r" +
"\n\t'#0099FF',\r" +
"\n\t'#00CC00',\r" +
"\n\t'#00CC33',\r" +
"\n\t'#00CC66',\r" +
"\n\t'#00CC99',\r" +
"\n\t'#00CCCC',\r" +
"\n\t'#00CCFF',\r" +
"\n\t'#3300CC',\r" +
"\n\t'#3300FF',\r" +
"\n\t'#3333CC',\r" +
"\n\t'#3333FF',\r" +
"\n\t'#3366CC',\r" +
"\n\t'#3366FF',\r" +
"\n\t'#3399CC',\r" +
"\n\t'#3399FF',\r" +
"\n\t'#33CC00',\r" +
"\n\t'#33CC33',\r" +
"\n\t'#33CC66',\r" +
"\n\t'#33CC99',\r" +
"\n\t'#33CCCC',\r" +
"\n\t'#33CCFF',\r" +
"\n\t'#6600CC',\r" +
"\n\t'#6600FF',\r" +
"\n\t'#6633CC',\r" +
"\n\t'#6633FF',\r" +
"\n\t'#66CC00',\r" +
The problem here is, of course, the + signs. How can these be "avoided"/removed?
I've tried to .split("+") but that doesn't work since the + signs aren't inside a pair of quotes.
the text file:
'#0000CC',
'#0000FF',
'#0033CC',
'#0033FF',
'#0066CC',
'#0066FF',
'#0099CC',
'#0099FF',
'#00CC00',
'#00CC33',
'#00CC66',
'#00CC99',
'#00CCCC',
'#00CCFF',
'#3300CC',
'#3300FF',
'#3333CC',
'#3333FF',
'#3366CC',
'#3366FF',
'#3399CC',
'#3399FF',
'#33CC00',
'#33CC33',
'#33CC66',
'#33CC99',
'#33CCCC',
'#33CCFF',
'#6600CC',
'#6600FF',
'#6633CC',
'#6633FF',
'#66CC00',
'#66CC33',
'#9900CC',
'#9900FF',
'#9933CC',
'#9933FF',
'#99CC00',
'#99CC33',
'#CC0000',
'#CC0033',
'#CC0066',
'#CC0099',
'#CC00CC',
Are you sure you are doing console.log?
I did console.log and didn't get any "+", but I got those when I use console.dir.
Anyway, these "+", are not part of the string and you can't remove them by using split.
And just use the string as if they were not there.
To get each line simply use:
const fs = require("fs");
let file = fs.readFileSync(__dirname + "/text.txt", { encoding: "utf8" });
const lines = file.split("\n");
I am quite new to NodeJs and need some help regarding flow.
So, I need to change some lib as it does not work for me. I have asny call and then right a way i have sync code. The thing is that sync code starts executing before asny part return data.
asny:
xmlenc.encrypt(message, options509, function(err, result) {
console.log("error:", err)
message = result
return message;
})
sync right after asyn:
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<" + envelopeKey + ":Envelope " +
xmlnsSoap + " " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
((self.soapHeaders || self.security) ?
(
"<" + envelopeKey + ":Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security && !self.security.postProcess ? self.security.toXML() : "") +
"</" + envelopeKey + ":Header>"
)
:
''
) +
"<" + envelopeKey + ":Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
(self.security && self.security.postProcess ? ' Id="_0"' : '') +
">" +
genXML() +
"</" + envelopeKey + ":Body>" +
"</" + envelopeKey + ":Envelope>";
How to solve this that the progrem with wait for asyn part to return before moving to sync part.
thank you
I'm using Java and generating an Excel file via Apache POI.
The following formula works perfect.
cell4.setCellFormula('(J' + (itemCountSize + 3) + '-H' + (itemCountSize + 3)+ ')')
Now I simply want to divide by the same H value eg. (J50-H50)/H50
cell4.setCellFormula('(J' + (itemCountSize + 3) + '-H' + (itemCountSize + 3)+ ')'+ '/H' + (itemCountSize + 3))
However it still just gives me (J50-H50)...
Any assistance would be appreciated.
Think you need an extra enclosing bracket
Have you tried:
cell4.setCellFormula('((J' + (itemCountSize + 3) + '-H' + (itemCountSize + 3)+ ')'+ '/H' + (itemCountSize + 3) + ')')
Or, simplifying with groovy string templating:
cell4.cellFormula = "((J${itemCountSize+3}-H${itemCountSize+3})/H${itemCountSize+3})" –
So I have this javascript function:
function show_courseline (course_index, repeats) {
var s = "";
var count = 0;
while (count < repeats) {
s = s + 'Number: ' + document.getElementById(course_index + count + 'a').innerHTML + '\n' +
'Semester: ' + document.getElementById(course_index + count + 'b').innerHTML + '\n' +
'Year: ' + document.getElementById(course_index + count + 'c').innerHTML + '\n' +
'Title: ' + document.getElementById(course_index + count + 'd').innerHTML + '\n' +
'Units: ' + document.getElementById(course_index + count + 'e').innerHTML + '\n' +
'Description: ' + document.getElementById(course_index + count + 'f').innerHTML + '\n';
++count;
}
alert(s);
}
But I get an error when I run it through an "onclick" input box. It has nothing to do with the document ids not being there, because they are.
Is course_index integer? If it is course_index + count is an integer and I know that ids cannot start with a digit