Try to search your question here, if you can't find : Ask Any Question Now ?

How to Remove Character ↵ in between two words of JavaScript String?

HomeCategory: stackoverflowHow to Remove Character ↵ in between two words of JavaScript String?
Avatarwillson asked 6 days ago

If I select two lines together and get text using window.getSelection().toString() then I get in between two words (last word from the upper line, and the first word of the lower word). Below is my code-

document.addEventListener('dblclick',function (event) {

var element = document.getElementsByClassName(event.target.parentElement.parentElement.parentElement.className);


var T= window.open("", "MsgWindow", "width=200,height=500");

T.document.write(element[0].innerText.replace(/n/g, "<br/>"));


T.document.write(`<script>
window.addEventListener("keydown", function(e){
if(e.keyCode === 16) {
var text = "";
if (window.getSelection) {
text_1 = window.getSelection().toString();
text = text_1.replace(/u21b5/g," "); // my attempt to corrrect
                        } 
words = text.split(" ");
console.log(words);
}
},false);
</script>`);
},false);

For example, if I select –

Sides

Section

and press shift key I get –

Array(1)
0: "Sides↵Section"
length: 1
__proto__: Array(0)

but the out put should be-

Array(1)
0: "Sides Section"
length: 1
__proto__: Array(0)

How can I replace with space?

PS: I have tried some possibilities based on solutions given on SE, but it didn’t work, plz don’t consider it trivial or duplicate post.

1 Answers
Best Answer
AvatarMikhail answered 6 days ago
Your Answer

20 + 4 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com