Detail refer to http://andrewu.co.uk/clj/entityencode/.
function TextToEntities(strPlainText, blnPartialEncodeOnly) {
var strPartial = [];
var strFull = [];
var intP = 0;
var intF = 0;
var objPartialRegExp = (new RegExp).compile("[\\w\\s]");
![](/Images/OutliningIndicators/InBlock.gif)
for (var intI=0; intI<strPlainText.length; ++intI) {
var strChar = strPlainText.charAt(intI);
var intChar = strChar.charCodeAt(0);
![](/Images/OutliningIndicators/InBlock.gif)
if (isNaN(intChar)) {
// IF CHAR FAILED TO DECODE, LEAVE AS CHAR
strPartial.push(strFull.push(strChar));
}
else {
var strEntity = "&#" + intChar + ";";
strFull.push(strEntity);
// IF CHAR WAS [a-zA-Z0-9_ \t] LEAVE AS CHAR, ELSE REPLACE WITH ENTITY
strPartial.push(objPartialRegExp.test(strChar) ? strChar : strEntity);
}
}
return (blnPartialEncodeOnly ? strPartial.join("") : strFull.join(""));
}
![](/Images/OutliningIndicators/None.gif)
function EntitiesToText(strEncodedText) {
var strData = String(strEncodedText);
var objRegExp = (new RegExp).compile("&#(\\d+);", "ig");
![](/Images/OutliningIndicators/InBlock.gif)
/* FOR EACH MATCH TO ANY ENTITY, REPLACE THAT
ENTITY GLOBALLY WITH ITS SINGLE CHAR EQUIVALENT */
while(strData.match(objRegExp)) {
var strCharMatch = RegExp.$1;
var objRegExpMatch = new RegExp("&#" + strCharMatch + ";", "ig");
strData = strData.replace(objRegExpMatch, String.fromCharCode(strCharMatch));
}
return strData;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)