|
This is appearing frequently in discussions. Have you done a search ?
|
|
|
|
|
Code:
foreach(int strAlternative in Suggest(arrWords[iCurrentCount]))-->Error Line
{
lbSuggestions.Items.Add(new ListItem(strAlternative, strAlternative));
}
|
|
|
|
|
what are contents of arrWords?
Is it a string array? If yes, 'strAlternative' is also string
rockram wrote: foreach(int strAlternative in Suggest(arrWords[iCurrentCount]))
I've a confusion with the above line.
Is arrWords a double dimension array?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
StrAlternative is an integer
Sutheesh Ramachandran
Cybernet Software Systems,
T Nagar, Chennai 17.
|
|
|
|
|
I meant, It should be a string
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Hello sir
Thanks for your reply
Here is my code:
using System;
using System.IO;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
partial class SpellSuggest : System.Web.UI.Page
{
private string[] strDictArray;
private bool boolDictionaryLoaded = false;
private int intErrors = 0;
protected void Page_Load(object sender, System.EventArgs e)
{
int iCurrentCount = 0;
string[] arrWords;
string strCompleteOriginal = "";
int iWordCount = 0;
//string hfOriginalString.Value, hfCurrentCount.Value, hfErrors.Value, hfWordCount.Value;
char[] chSplit ={ ' ' };
//string strAlternative = "";
int i = 0;
string strText;
strText = Request.QueryString["txtContent"];
strText = strText.Trim();
// If nothing to check, exit the procedure
if (strText == "")
{
return; // TODO: might not be correct. Was : Exit Sub
}
else
{
// Get the string to check
strCompleteOriginal = strText;
}
// First time the page is loaded
if (!IsPostBack)
{
// Initialize current word index to zero
iCurrentCount = 0;
// Initialize total word count to zero
iWordCount = 0;
// Initialize total invalid word count to zero
intErrors = 0;
// Set value of hidden field containing complete original string to check
hfOriginalString.Value = strCompleteOriginal;
// Set value of hidden field containing current index
hfCurrentCount.Value = "0";
// Split into an array of individual words
arrWords = strCompleteOriginal.Split(chSplit);
// Count total number of words
iWordCount = arrWords.Length;
// Set value of hidden field containing total number of words
hfWordCount.Value = Convert.ToString(iWordCount);
// Set value of hidden field containing total number of invalid words
hfErrors.Value = "0";
}
else
{
// Not the first time, split hidden field into an array of individual words
arrWords = hfOriginalString.Value.Split(chSplit);
// Get index for current word in the array
iCurrentCount = Convert.ToInt32(hfCurrentCount.Value);
// Get current number of invalid words from hidden field
intErrors = int.Parse(hfErrors.Value);
}
// Set the current word being checked textbox value
txtCurrent.Text = arrWords[iCurrentCount];
// User has chosen to stop searching
if (Request.Form["cmdCancel"] == "Stop")
{
// Get our array of words from hidden field
arrWords = hfOriginalString.Value.Split(chSplit);
// Get total number of words from hidden field
iWordCount = Convert.ToInt32(hfWordCount.Value);
// Start with the words already corrected
string strReplace = hfFinal.Value;
int j = 0;
// Now add the rest of the un-checked words
for (j = iCurrentCount; j <= iWordCount - 1; j++)
{
strReplace += arrWords[j] + " ";
}
// The last invalid word was never fixed
intErrors -= 1;
// Notify the user and close the spell check window
stopChecking("frmSpellCheck", "txtContent", strReplace);
// Exit the procedure, we're done
return; // TODO: might not be correct. Was : Exit Sub
}
// If we're returning from a suggestion that has been selected or a manually
// entered word
if (Request.Form["cmdNext"] == "Next")
{
// Get our array of words from hidden field
arrWords = hfOriginalString.Value.Split(chSplit);
// Get total number of words from hidden field
iWordCount = Convert.ToInt32(hfWordCount.Value);
// If the user has selected a suggestions form the list
if (txtManual.Text == "")
{
// Update word in array
arrWords[iCurrentCount] = lbSuggestions.SelectedValue;
// Append corrected word to string containing completed valid text
hfFinal.Value += lbSuggestions.SelectedValue + " ";
}
else
{
// If the user has manually entered the word
// Update word in array
arrWords[iCurrentCount] = txtManual.Text;
// Append corrected word to string containing completed valid text
hfFinal.Value += txtManual.Text + " ";
}
// Clear out the Current word and manual word textboxes, ready for the next one
txtManual.Text = "";
txtManual.Text = "";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
// Now carry on checking the rest of the text
for (i = iCurrentCount; i <= iWordCount - 1; i++)
{
// Set the value of the current word being checked textbox
txtCurrent.Text = arrWords[iCurrentCount];
LoadDictArray("dict-large.txt", arrWords[iCurrentCount].Substring(0));
// If the current word contains non-text characters, just add to the final string and move on
if (PrepForSpellCheck(arrWords[iCurrentCount]) == false)
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the current word is a number, just add to the final string and move on
else if (IsNumeric(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the word is valid, just add to the final string and move on
else if (SpellCheck(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
else
{
// Increment the number of invalid words
intErrors += 1;
// Set the hidden field containing the number of invalid words
hfErrors.Value =Convert.ToString(intErrors);
// Invalid word, suggest some alternatives
// Clear out list from previous suggestions
lbSuggestions.Items.Clear();
// Add each suggested word to the list
foreach(string strAlternative in Suggest(arrWords[iCurrentCount]))
{
lbSuggestions.Items.Add(new ListItem(strAlternative, strAlternative));
}
// add the original item to the list of suggestions in case it's not in our dictionary
lbSuggestions.Items.Insert(0, new ListItem(arrWords[iCurrentCount], arrWords[iCurrentCount]));
// select the original item in the list by default
lbSuggestions.SelectedIndex = 0;
break; // TODO: might not be correct. Was : Exit For
}
}
// If we've checked all the words in the original text
if (iCurrentCount == iWordCount)
{
// Notify the user and close the spell check window
finishedChecking("frmSpellCheck", "txtContent", hfFinal.Value);
}
// Exit the procedure, we're done
return; // TODO: might not be correct. Was: Exit Sub
}
// check the current word and if invalid, suggest alternatives
for (i = 0; i <= iWordCount - 1; i++)
{
txtCurrent.Text = arrWords[iCurrentCount];
LoadDictArray("dict-large.txt", String.Left(arrWords[iCurrentCount], 1));
// If the current word contains non-text characters, just add to the final string and move on
if (PrepForSpellCheck(arrWords[iCurrentCount]) == false)
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value = Convert.ToString(iCurrentCount);
}
// If the current word is a number, just add to the final string and move on
else if (Information.IsNumeric(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value =Convert.ToString(iCurrentCount);
}
// If the word is valid, just add to the final string and move on
else if (SpellCheck(arrWords[iCurrentCount]))
{
hfFinal.Value += arrWords[iCurrentCount] + " ";
// Increment the current word index
iCurrentCount += 1;
// Set the hidden field containing the current index
hfCurrentCount.Value =Convert.ToString(iCurrentCount);
}
else
{
// Increment the number of invalid words
intErrors += 1;
// Set the hidden field containing the number of invalid words
hfErrors.Value =Convert.ToString(intErrors);
// Invalid word, suggest some alternatives
// Clear out list from previous suggestions
lbSuggestions.Items.Clear();
// Add each suggested word to the list
foreach (string strAlternative in Suggest(arrWords[iCurrentCount]))
{
lbSuggestions.Items.Add(new ListItem(strAlternative, strAlternative));
}
// add the original item to the list of suggestions in case it's not in our dictionary
lbSuggestions.Items.Insert(0, new ListItem(arrWords[iCurrentCount], arrWords[iCurrentCount]));
// select the original item in the list by default
lbSuggestions.SelectedIndex = 0;
// Exit the loop so that the user can select a suggestion or
// type their corrected word
break; // TODO: might not be correct. Was : Exit For
}
}
// If we've checked all the words in the original text
if (iCurrentCount == iWordCount)
{
// Notify the user and close the spell check window
finishedChecking("frmSpellCheck", "txtContent", hfFinal.Value);
}
}
private void stopChecking(string strFormName, string strTextboxName, string strText)
{
// Hide the table with the current word and suggestions
tblMain.Visible = false;
// Insert the onload javascript to alert the user that the check has completed
// and update the source textbox and close the spellchecker window
StringBuilder sbJavascript = new StringBuilder();
sbJavascript.Append("<script language=\"javascript\" type=\"text/javascript\">");
sbJavascript.Append("alert(\"The spell check was stopped successfully (" + intErrors + " error(s) were fixed).\");");
sbJavascript.Append("window.opener." + strFormName + "." + strTextboxName + " = '" + strText + "';");
sbJavascript.Append("window.opener." + strFormName + ".cmdCheckSpelling.disabled = false;");
sbJavascript.Append("self.close();");
sbJavascript.Append("</script>");
Page.ClientScript.RegisterStartupScript(System.Type.GetType("System.String"), "onload", sbJavascript.ToString);
}
private void finishedChecking(string strFormName, string strTextboxName, string strText)
{
// Hide the table with the current word and suggestions
tblMain.Visible = false;
// Insert the onload javascript to alert the user that the check has completed
// and update the source textbox and close the spellchecker window
StringBuilder sbJavascript = new StringBuilder();
sbJavascript.Append("<script language=\"javascript\" type=\"text/javascript\">");
sbJavascript.Append("alert(\"The spell check has completed successfully (" + intErrors + " error(s) found).\");");
sbJavascript.Append("window.opener." + strFormName + "." + strTextboxName + " = '" + strText + "';");
sbJavascript.Append("window.opener." + strFormName + ".cmdCheckSpelling.disabled = false;");
sbJavascript.Append("self.close();");
sbJavascript.Append("</script>");
Page.ClientScript.RegisterStartupScript(System.Type.GetType("System.String"), "onload", sbJavascript.ToString);
}
private void LoadDictArray(string strPath, string strBegin)
{
bool boolStart = false;
string strCurrent = "";
string strFinal = "";
// Open our dictionary file
StreamReader srDictionary = new StreamReader(HttpContext.Current.Server.MapPath(strPath));
// Check each line and loop while there is another
while (srDictionary.Peek() != -1)
{
// Read the current line
strCurrent = srDictionary.ReadLine();
// Does the first character match our word's
if (String.LCase(String.Left(strCurrent, 1)) == String.LCase(strBegin))
{
boolStart = true;
// Only add words beginning with the same letter as the current word
strFinal += strCurrent + Constants.vbNewLine;
}
// Exit, we have all our relevant words
if(boolStart == true & String.LCase(String.Left(strCurrent, 1)) != String.LCase(strBegin))
{
break; // TODO: might not be correct. Was : Exit While
}
}
// Close the streamreader
srDictionary.Close();
// Split our string into an array of suitable words
strDictArray = String.Split(strFinal, Constants.vbNewLine);
strCurrent.Substring(1).ToLower() == strBegin.ToLower());
}
private bool PrepForSpellCheck(string strWord)
{
string strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-";
int i = 0;
string strLetter = "";
bool boolValid = false;
for (i = 1; i <= String.Len(strWord); i++)
{
strLetter = String.Mid(strWord, i, 1);
if (String.InStr(strValidChars, strLetter) > 0)
{
boolValid = true;
}
else if (i < String.Len(strWord))
{
boolValid = false;
break; // TODO: might not be correct. Was : Exit For
}
}
return boolValid;
}
private bool SpellCheck(string strWord)
{
int iFirst;
int iLast;
int iMiddle;
bool retValue = false;
if (String.Len(strWord) > 1)
{
iFirst = Information.LBound(strDictArray);
iLast = Information.UBound(strDictArray);
while (iFirst <= iLast)
{
iMiddle = (iFirst + iLast) / 2;
if (String.LCase(strDictArray(iMiddle)) == String.LCase(strWord))
{
retValue = true;
break; // TODO: might not be correct. Was : Exit Do
}
else if (String.LCase(strDictArray(iMiddle)) < String.LCase(strWord))
{
iFirst = iMiddle + 1;
}
else
{
iLast = iMiddle - 1;
}
}
}
else
{
retValue = true;
}
return retValue;
}
private string Soundex(string strString)
{
int i;
string strLetter;
string strCode;
string strSoundex = "";
strSoundex = String.UCase(String.Left(strString, 1));
for (i = 2; i <= String.Len(strString); i++)
{
strLetter = String.UCase(String.Mid(strString, i, 1));
switch (strLetter)
{
case "B":
case "P":
strCode = "1";
break;
case "F":
case "V":
strCode = "2";
break;
case "C":
case "K":
case "S":
strCode = "3";
break;
case "G":
case "J":
strCode = "4";
break;
case "Q":
case "X":
case "Z":
strCode = "5";
break;
case "D":
case "T":
strCode = "6";
break;
case "L":
strCode = "7";
break;
case "M":
case "N":
strCode = "8";
break;
case "R":
strCode = "9";
break;
default:
strCode = "";
break;
}
if (String.Right(strSoundex, 1) != strCode)
{
strSoundex = strSoundex + strCode;
}
}
return strSoundex;
}
private int WordSimilarity(string strWord, string strSimilarWord)
{
int functionReturnValue = 0;
int intWordLen;
int intSimilarWordLen;
int intMaxBonus;
int intPerfectValue;
int intSimilarity;
int i;
intWordLen = String.Len(strWord);
intSimilarWordLen = String.Len(strSimilarWord);
intMaxBonus = 3;
intPerfectValue = intWordLen + intWordLen + intMaxBonus;
intSimilarity = intMaxBonus - Abs(intWordLen - intSimilarWordLen);
for (i = 1; i <= intWordLen; i++)
{
if (i <= intSimilarWordLen)
{
if (String.LCase(String.Mid(strWord, i, 1)) == String.LCase(String.Mid(strSimilarWord, i, 1)))
{
intSimilarity = intSimilarity + 1;
}
if (String.LCase(String.Mid(strWord, intWordLen - i + 1, 1)) == String.LCase(String.Mid(strSimilarWord, intSimilarWordLen - i + 1, 1)))
{
intSimilarity = intSimilarity + 1;
}
}
}
functionReturnValue = intSimilarity / intPerfectValue;
return functionReturnValue;
return functionReturnValue;
}
private string[] Suggest(string strWord)
{
string[] functionReturnValue = null;
string strSoundex = "";
int i = 0;
string strSuggestions = "";
int intMaxSuggestions = 0;
int intSuggestionCount = 0;
string strSuggestion = "";
string[] strSuggestionArray;
double[] dblSimilarityArray;
double dblSimilarity = 0;
intMaxSuggestions = 10;
strSoundex = Soundex(strWord);
while (i <= Information.UBound(strDictArray))
{
if (Strings.LCase(Strings.Left(strDictArray(i), 1)) != Strings.LCase(Strings.Left(strWord, 1)))
{
i = i + 1;
}
else
{
break; // TODO: might not be correct. Was : Exit Do
}
}
while (i <= Information.UBound(strDictArray))
{
if (Strings.LCase(Strings.Left(strDictArray(i), 1)) == Strings.LCase(Strings.Left(strWord, 1)))
{
if (Soundex(strDictArray(i)) == strSoundex)
{
if (strSuggestions + "" == "")
{
strSuggestions = strDictArray(i);
}
else
{
strSuggestions = strSuggestions + "|" + strDictArray(i);
}
}
i = i + 1;
}
else
{
break; // TODO: might not be correct. Was : Exit Do
}
}
functionReturnValue = Strings.Split(strSuggestions, "|");
if (Information.UBound(functionReturnValue) < intMaxSuggestions)
{
intSuggestionCount = Information.UBound(functionReturnValue);
}
else
{
intSuggestionCount = intMaxSuggestions - 1;
}
// ERROR: Not supported in C#: ReDimStatement
// ERROR: Not supported in C#: ReDimStatement
foreach ( strSuggestion in functionReturnValue)
{
dblSimilarity = WordSimilarity(strWord, strSuggestion);
i = intSuggestionCount;
while (dblSimilarity > dblSimilarityArray(i))
{
if (i < intSuggestionCount)
{
strSuggestionArray(i + 1) = strSuggestionArray(i);
dblSimilarityArray(i + 1) = dblSimilarityArray(i);
}
strSuggestionArray(i) = strSuggestion;
dblSimilarityArray(i) = dblSimilarity;
i = i - 1;
if (i == -1)
{
break; // TODO: might not be correct. Was : Exit Do
}
}
}
functionReturnValue = strSuggestionArray;
return functionReturnValue;
return functionReturnValue;
}
}
if possible u can help me
This is regarding spellcheck
|
|
|
|
|
rockram wrote: Suggest(arrWords[iCurrentCount])
Your method might be returning a string.
|
|
|
|
|
I use the below code for null checking..
if (document.getElementById("<%=txtHeading.ClientID%>").value=="")
{
alert("Enter News Heading");
}
But when the user hit the space button , it become false..
So. Give me the code for chking One or more space through js ?
Got ?Give..
|
|
|
|
|
You must trim the string
<br />
if (trim(document.getElementById("<%=txtHeading.ClientID%>").value)=="")<br />
{<br />
alert("Enter News Heading");<br />
}<br />
<br />
function trim(stringToTrim) {<br />
return stringToTrim.replace(/^\s+|\s+$/g,"");<br />
}<br />
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
|
Use a RequiredFieldValidator . It don't allow spaces.
|
|
|
|
|
great
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
I Have done a small C# Application in UserControl, then i taken that DLL into our webapplication then i make it as ActiveX in the Help of
<object ..........=""> tag it's working fine..........
But second time i just add the some COM components into C# application usercontrol then i make as a ActiveX but this time I couldn't get the corresponding usercontrol into my Web application...........
Is it there any other Tag i've import into web application for work out this kind of Concepts..........
|
|
|
|
|
Hi i have multiple user type in webconfig file appsettings like this:
<add key="Admin" value="Admin" />
<add key="User" value="User" />
How to bind this values in to my dropdownlistbox?,
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
modified on Friday, July 4, 2008 1:06 AM
|
|
|
|
|
loop
I don't know how to write my signture!
|
|
|
|
|
what loop?,
What ur trying to say?,
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
|
|
|
|
|
How to add this User types in to my dropdown list:
<add key="UserType" value="Admin,User,Guest"/>
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
|
|
|
|
|
Try this
<br />
Dim str As String = ConfigurationSettings.AppSettings("UserType")<br />
<br />
DropDownList1.DataSource = str.Split(",")<br />
<br />
DropDownList1.DataBind()<br />
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
Hey Sorry i got o/p,
Thank u
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
|
|
|
|
|
Its a vb.net code, I think you are using C#.
make some syntax change, It will work
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
String str = ConfigurationSettings.AppSettings["UserType"];
DropDownList1.DataSource = str.Split(',');
DropDownList1.DataBind();
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
I have a editable grid in which i have to format some numbers, I have to display numbers in Number format( ex. 1,233) and decimals in Decimal format (Ex: 1,233.45). Now I am displaying using this format({0,0.00}). But my problem is it is displaying the numbers also in decimals (ex: 1,233.00). How can i display numbers in number format and decimals in decimal format.. Is there any format string for displaying like this..
Thanks In advance
Satish Reddy.D
Satish Reddy.D
|
|
|
|
|
how to deploying mutiple web application in one setup ?
|
|
|
|
|
I am using asp.net with c#.In my project i am using master page .Each form are child of this master page.I want to check textbox null in clild master page using javascript.
I use the following code to check null.
butSubmit.Attributes.Add("OnClick", "return val()");
function val()
{
if(document.getElementById("TextBox1").value=="")
{
return;
}
}
but its not working.If, without using the master page it work properly.In my child master page there is no form tag.Because in my master page i use teeview so form tag is placed in master page.If anyone understand my probelm pls .
|
|
|
|
|
Where the text box is? In Master page or content page(child page)?
deepthy.p.m wrote: I want to check textbox null in clild master page using javascript.
How many master pages are there?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|