Knowledgebase Home Page  >  RapidSpell Web ASP.NET  >  Behavior Customization
Search the Knowledge Base
How can I disallow ALL CAPS in text that is spell checked? (C#)
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=135&catId=55

Options

Print this page
Email this to a friend

Through a simple subclass, you can completely control the logic behind which words are accepted and which are not.  The logic doesn't have to use our dictionaries, but it can.

 

 

1. Add this class to the project.

 

class MyRapidSpellChecker : Keyoti.RapidSpell.RapidSpellChecker

{

public MyRapidSpellChecker(string licenseKey):base(licenseKey){}

protected override bool LookUpMainDictionary(string word)

{

if(word == word.ToUpper()) return false;//dont allow ALL CAPS

return base.LookUpMainDictionary(word);

}

protected override bool LookUpUserDictionary(string word)

{

if(word == word.ToUpper()) return false;//dont allow ALL CAPS

return base.LookUpUserDictionary(word);

}

public override System.Collections.ArrayList FindSuggestions(string word)

{

if(word == word.ToUpper()) //error was an ALL CAPS, so suggest a lowercase version

{

if(this.LookUp(word.ToLower()))

{

return new System.Collections.ArrayList(new string[]{word.ToLower()});

}

}

return base.FindSuggestions(word);

}

}

 

2. Use this code by setting CheckerEngine in the codebehind of either; the page holding RapidSpellWInlineHelper or the page holding RapidSpellWeb;

 

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

this.RapidSpellWInlineHelper1.CheckerEngine = new MyRapidSpellChecker("...your license key....");

//--or

this.RapidSpellWeb.CheckerEngine = new MyRapidSpellChecker("...your license key...");

}

 

That should do it.  This will warn users about using ALL CAPS and suggest the lowercase version.

 

 

Here's the complete codebehind from our "rswihelper.aspx" page.

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace RapidSpellWeb_Demo_CSharp

{

///

/// Summary description for rswihelper.

///

public class rswihelper : System.Web.UI.Page

{

protected Keyoti.RapidSpell.RapidSpellWInlineHelper RapidSpellWInlineHelper1;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

this.RapidSpellWInlineHelper1.CheckerEngine = new MyRapidSpellChecker("5752675E645A665F68596A69615A66383F413C42383E413B483D4342434A424E504B515");

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

class MyRapidSpellChecker : Keyoti.RapidSpell.RapidSpellChecker

{

public MyRapidSpellChecker(string licenseKey):base(licenseKey){}

protected override bool LookUpMainDictionary(string word)

{

if(word == word.ToUpper()) return false;//dont allow ALL CAPS

return base.LookUpMainDictionary(word);

}

protected override bool LookUpUserDictionary(string word)

{

if(word == word.ToUpper()) return false;//dont allow ALL CAPS

return base.LookUpUserDictionary(word);

}

public override System.Collections.ArrayList FindSuggestions(string word)

{

if(word == word.ToUpper()) //error was an ALL CAPS, so suggest a lowercase version

{

if(this.LookUp(word.ToLower()))

{

return new System.Collections.ArrayList(new string[]{word.ToLower()});

}

}

return base.FindSuggestions(word);

}

}

}

 


Related Questions:

Attachments:

No attachments were found.