Text==>u r input Value,,,,,Lenth==>Lenth of words to be check
public int ValidateWords(string Text, int Length)
{
int result = 0;
bool lastWasSpace = false;
foreach (char c in Text)
{
if (char.IsWhiteSpace(c))
{
if (lastWasSpace == false)
{
result++;
}
lastWasSpace = true;
}
else
{
// Count other characters every time.
//result++;
lastWasSpace = false;
}
}
if (result <= Length && result > 0)
{
return 1;
}
else if (result > Length)
{
return -1;
}
else
{
return 0;
}
}
Its use for me Thanks
ReplyDelete