Palindrome

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Palindrome as PDF for free.

More details

  • Words: 293
  • Pages: 3
using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Linq; System.Text; System.Web; System.Web.UI; System.Web.UI.WebControls;

namespace CustomControlLibrary { [DefaultProperty("Text")] [ToolboxData("<{0}:PalindromeCheckerRenderedControl runat=server>")] public class PalindromeCheckerRenderedControl : WebControl { public event EventHandler PalindromeFound; [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"] = value; if (this.CheckForPalindrome()) { if (PalindromeFound != null) { PalindromeFound(this, EventArgs.Empty); } } } } protected override void RenderContents(HtmlTextWriter output) { if (this.CheckForPalindrome()) { output.Write("This is Palindrome:
"); output.Write(@"<span style= 'font-style: bold;font-size: xlarge; color:Blue;'>"); output.Write(Text); output.Write(""); output.Write(""); } else {

Page | 1

output.Write("This is not a Palindrome:
"); output.Write(@""); output.Write(""); output.Write(Text); output.Write(""); output.Write(""); }

}

protected string StripNonAlphanumerics(string str) { string strStripped = (String)str.Clone(); if (str != null) { char[] rgc = strStripped.ToCharArray(); int i = 0; foreach (char c in rgc) { if (char.IsLetterOrDigit(c)) { i++; } else { strStripped = strStripped.Remove(i, 1); } } } return strStripped; } protected bool CheckForPalindrome() { if (this.Text != null) { String strControlText = this.Text; String strTextToUpper = null; strTextToUpper = Text.ToUpper(); strControlText = this.StripNonAlphanumerics(strTextToUpper); char[] rgcReverse = strControlText.ToCharArray(); Array.Reverse(rgcReverse); String StrReverse = new string(rgcReverse); if (strControlText == StrReverse) { return true; } else { return false; } } else { return false; } }

Page | 2

} } protected void RenderPalindromesInTable(HtmlTextWriter output) { output.AddAttribute(HtmlTextWriterAttribute.Width, "50%"); output.AddAttribute(HtmlTextWriterAttribute.Border, "1"); output.RenderBeginTag(HtmlTextWriterTag.Table); foreach (string s in this.alPalindromes) { output.RenderBeginTag(HtmlTextWriterTag.Tr); output.AddAttribute(HtmlTextWriterAttribute.Align, "left"); output.AddStyleAttribute(HtmlTextWriterStyle.FontSize,"medium ");

output.AddStyleAttribute(HtmlTextWriterStyle.Color, "blue"); output.RenderBeginTag(HtmlTextWriterTag.Td); output.Write(s); output.RenderEndTag(); output.RenderEndTag(); } output.RenderEndTag(); }

protected override void RenderContents(HtmlTextWriter output) { if (this.CheckForPalindrome()) { output.Write("This is Palindrome:
"); output.RenderBeginTag(HtmlTextWriterTag.Font); output.AddStyleAttribute(HtmlTextWriterStyle.Color, "blue"); output.RenderBeginTag(HtmlTextWriterTag.B); output.Write(Text); output.RenderEndTag(); output.RenderEndTag(); } else { output.Write("This is Not a Palindrome:
"); output.RenderBeginTag(HtmlTextWriterTag.Font); output.AddStyleAttribute(HtmlTextWriterStyle.Color, "red"); output.RenderBeginTag(HtmlTextWriterTag.B); output.Write(Text); output.RenderEndTag(); output.RenderEndTag(); } output.Write("
"); RenderPalindromesInTable(output); }

Page | 3

Related Documents

Palindrome
June 2020 9
Palindrome
May 2020 6
Palindrome Poem
June 2020 9
Longest Palindrome
November 2019 9