I have string like this:
var content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
The sentence will be displayed in the left flat html format, like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
How I can substitute any remaining extra blank space at the end of the line to negative (-) characters using JavaScript which makes the sentence become aligned justified so I get results like this?
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore- eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia-------- deserunt mollit anim id est laborum.-----------------------------------------------------------------------------------
The output should be something like this output
The original formatting of the report MUST be retained, so changing it is not allowed
I tried to achieve that using this code jsfiddle
var html = content.split(" ");
var htmlTmp = "";
var result = "";
var limitlength = 40;
var linelength = 50;
for(var i=0; i< html.length; i++) {
var htmlTmp_length = htmlTmp.length;
if(htmlTmp_length > limitlength) {
result += html[i] + " ";
if(htmlTmp_length < linelength) {
for(j=0;j<(linelength - htmlTmp_length);j++) {
result += "-";
}
}
result += "<br/>";
htmlTmp = "";
}
else {
result += html[i] + " ";
htmlTmp += html[i] + " ";
}
}
$(".content2").html(result);
but it does not seem to work, as each letter takes up different space.
text-align: justify; text-align-last: justify; white-space: pre
– minmaxavg