This is a migrated thread and some comments may be shown as answers.

GetStatisticsInfo is counting non-breaking spaces as words

4 Answers 72 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Bob asked on 22 Feb 2021, 03:39 PM

Hello, we recently implemented a word count feature in the RadRichTextBox by using the GetStatisticsInfo method of the RadDocument class.  We noticed word counts are not accurate and determined that the document contained some non-breaking spaces (0xA0) instead of normal spaces (0x20), and when these non-breaking spaces were positioned in span text separately like this: <t:Paragraph> <t:Span Text=" " /> </t:Paragraph>, then the word count included this as a word.

Since we can't control the document content that is imported, we could work around this issue by replacing the non-breaking spaces with normal spaces before getting a word count, but I am not sure of the best approach for doing so.  Please let me know a solution for the replacement, or if this is something you will be fixing at some point.

 

Thanks,

Bob

4 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 23 Feb 2021, 02:19 PM

We have also determined that if a non-breaking space is placed between two words, then the count is one word instead of two.  To work around this issue for now, I have done a simple replace on the imported text string.

private string FixupNonBreakingSpaces(string textToFix)
{
    return textToFix.Replace(Convert.ToChar(160), ' ');
}
0
Accepted
Martin
Telerik team
answered on 24 Feb 2021, 03:16 PM

Hello Bob,

Thank you for the information provided and for the suggested workaround.

Both the scenarios are related to a currently not supported functionality that we have logged in our backlog: RichTextBox: Support for Non-Breaking Spaces. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button so you can receive updates when its status changes.

I hope you find this information helpful.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 24 Feb 2021, 03:31 PM

Thank you Martin, I have upvoted the issue.

I also changed the workaround slightly to handle directly imported or pasted content from Html:

private string FixupNonBreakingSpaces(string textToFix)
{
    return textToFix.Replace(Convert.ToChar(160), ' ').Replace("&nbsp;", " ");
}
0
Martin
Telerik team
answered on 25 Feb 2021, 09:45 AM

Hello Bob,

Thank you again! Do not hesitate to contact us if any additional questions arise.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
RichTextBox
Asked by
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Martin
Telerik team
Share this question
or