(Q) How to copy (thousands of) carriage returns
(not new lines
) from one textarea to another?
I used the script below to check for "broken characters".
And apparently the carriage return
is the only character that won't copy correctly.
I would like to avoid substituting.
(Edit 1)
Carriage returns (code 13)
automatically get converted to "\n"
.
"\n".charCodeAt(0);
returns 10
.
I need it to return 13
.
(Q) Is there a way to convert all carriage returns
that got converted to new lines
back to carriage returns
, without converting new lines
that are not converted from a carriage return
?
(Edit 2)
It seems like I will have to use a substitute
for carriage returns
.
(Q) Any suggestions?
function getListOfChars()
{
let arrayOfChars = [];
for(let charCode = 0; charCode < 65536 /*1114112*/; charCode++)
{
arrayOfChars.push(String.fromCharCode(charCode));
//arrayOfChars.push(String.fromCodePoint(charCode));
}
return arrayOfChars;
}
function getBrokenChars()
{
let listOfChars = getListOfChars();
let listOfBrokenChars = [];
let char;
let textareaValue;
let textareaValueCharCode;
for(let x = 0; x < listOfChars.length; x++)
{
char = listOfChars[x];
document.getElementById('textarea').value = char;
textareaValue = document.getElementById('textarea').value;
textareaValueCharCode = textareaValue.charCodeAt(0);
//textareaValueCharCode = textareaValue.codePointAt(0);
if(x !== textareaValueCharCode)
{
listOfBrokenChars.push(char);
console.log("\"" + char + "\"" + " (" + x + ")" + " -> " + "\"" + textareaValue + "\"" + " (" + textareaValueCharCode + ")");
}
}
return listOfBrokenChars;
}
let brokenChars = getBrokenChars();
<!DOCTYPE html>
<html>
<head>
<title>Fix Bug Char Codes</title>
</head>
<body>
<textarea id="textarea">a</textarea>
</body>
<script src="fixBugCharCodes.js"></script>
</html>