Document.write should only be used as the page is being loaded (parsed), otherwise it will overwrite the page, hopefully you understand this. Assuming that you do, you could do:
Code:
var separated = "HelloWorld".replace(/(\S)([A-Z])/g, "$1 $2");
document.write(separated);
In place of "HelloWorld"
in the above, you could use any variable containing a string value:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">
var bob='NannyMcFee';
var separated = bob.replace(/(\S)([A-Z])/g, "$1 $2");
document.write(separated);
</script>
</body>
</html>
Which also demonstrates that this is not always the optimal way to parse a string with no spaces.
Bookmarks