noSpace(event: any, docId: string) { // Muss richtig gemacht !
let str = String.fromCharCode(event.charCode);
let clipBoardStr = event.clipboardData.getData('text/plain');
let s = clipBoardStr.replace(/ /g , '');
setTimeout( function() {
(<HTMLInputElement> document.getElementById(docId)).value = s;
}, 100);
}
I want to have the text without any white spaces.
This works perfectly on Firefox and Chrome, but not in Internet Explorer :(
could you try to change your regexp to /\\s+/g ?
let s = clipBoardStr.replace(/\s+/g , '');
the meta \\s match any whitespace character https://www.w3schools.com/jsref/jsref_regexp_whitespace.asp
let clipBoardStr;
if (window.clipboardData && window.clipboardData.getData) {
clipBoardStr = window.clipboardData.getData('Text');
} else {
clipBoardStr = event.clipboardData.getData('text/plain');
}
And this is the way to do it!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.