What I'm trying to do is mark the red dashed underline for each misspellings present in the web browser control that I used in my winform application.
Here is my code snippet: -
public static string CheckSpelling(string InnerHTML)
{
string Val = "";
try
{
StringBuilder strBu = new StringBuilder();
strBu.Append(InnerHTML);
RemoveStyleAssigned(ref strBu);
for (int i = 0; i < strBu.Length; i++)
{
if (Convert.ToString(strBu[i]).ToLower() == "<")
{
for (int j = i + 1; j < strBu.Length; j++)
{
if (Convert.ToString(strBu[j]).ToLower() == ">")
{
i = j;
for (int k = j + 1; k < strBu.Length; k++)
{
if (Convert.ToString(strBu[k]).ToLower() != " ")
{
i = k;
CheckAndReplace(ref strBu, ref i);
break;
}
}
break;
}
}
}
else if (Convert.ToString(strBu[i]).ToLower() != " ")
{
CheckAndReplace(ref strBu, ref i);
}
}
Val = strBu.ToString();
}
catch (Exception ex)
{
}
return Val;
}
Here, InnerHTML is the InnerHTML of a web browser control obtained for the entered data. Next Method - CheckandReplace
private static void CheckAndReplace(ref StringBuilder strBu, ref int i)
{
try
{
string Target = string.Empty;
string NewString = "";
for (int j = i; j <= strBu.Length; j++)
{
if (j == strBu.Length || Convert.ToString(strBu[j]).ToLower() == " " || Convert.ToString(strBu[j]).ToLower() == "<" )
{
string Wordtocheck = ReplaceXmlCharacters(Target);
if (!IsSpellingCorrect(Wordtocheck))
{
NewString = "<u style='text-decoration: none; border-bottom: 1px dotted #FF0000'>" + Target + "</u>";
strBu = strBu.Replace(Target, NewString, i, Target.Length);
i += NewString.Length - 1;
}
else
{
i = j - 1;
}
break;
}
else
Target += strBu[j];
}
}
catch (Exception ex)
{
}
}
The main problem is that everything works fine with the above code, but whenever I get any special character or any space in the target value, the above code also highlights the same, but I don't want to allocate this as done in MS Word. Please guide me through this or their other way out.
Thanks in advance