Encode Strings

Encode Strings

Encode Strings C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string company = "The Inside Corner, Inc.";
byte[] encodedBytes = Sitecore.StringUtil.Encode(company);
System.Text.StringBuilder builder = new System.Text.StringBuilder();

foreach (byte element in encodedBytes)
builder.Append(element);
string decodedString = Sitecore.StringUtil.Decode(encodedBytes);

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Original String", "<b>" + company + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Hash Code", "<b>" + company.GetHashCode().ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Type Code", "<b>" + company.GetTypeCode().ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Encoded String", "<b>" + builder.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Decoded String", "<b>" + decodedString + "</b>");

output.RenderEndTag(); //Div

Encode Strings C# Web Control Output

Item: Encode Strings

Original String: The Inside Corner, Inc.
Hash Code: 580850890
Type Code: String
Encoded String: 84104101327311011510510010132671111141101011144432731109946
Decoded String: The Inside Corner, Inc.