Prevent HTML Removing Successive Spaces
I have an issue in a JSP page where I have to display a generated message onscreen based on a string. It all works fine until one of the account numbers contains two spaces. So, I
Solution 1:
white-space: break-spaces
solved for me. More on white-spaces here. They have this awesome table:
Solution 2:
function encodeWhiteSpaces(str) {
return str.split('').map(function(c) { return c === ' ' ? ' ' : c }).join('');
}
The string is converted to an array(split
), then created a new arrray (map
) with all white spaces converted to
, finally join the array back to a string (join
).
Solution 3:
Replace spaces with
if they're copied/pasted on the front-end they're treated the same as spaces.
Post a Comment for "Prevent HTML Removing Successive Spaces"