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

RadEditor Character Count Mismatch

3 Answers 126 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Education
Top achievements
Rank 1
Education asked on 21 Feb 2014, 05:44 AM
The RadEditor on screen Character Count doesn't match the character count when accessing RadEditor1.Text.Length on a postback.  How can I access the count that is displayed to the user as they are entering text?

Below is an example:

Screen shows 21 characters, but when doing RadEditor1.Text the result is :"0123456789 \n0123456789"
This has a .Length of 22 characters.



3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Feb 2014, 06:30 AM
Hi,

Please try the following code snippet to achieve your scenario.

C#:
string editortext = RadEditor1.Text;
int count = editortext.Split('\n').Length - 1;
int len = (RadEditor1.Text.Length) - (count * 2);

Thanks,
Princy.
0
Education
Top achievements
Rank 1
answered on 21 Feb 2014, 07:21 AM
Is there any way to just pull that exact character count value from the control?

I used something similar to your solution:
int newLineCount = RadEditor1.Text.Split('\n').Length - 1;
int characterCount = (RadEditor1.Text.Length - newLineCount);

The proposed solution only works when it is a new line, but there are many other escape sequences that would need to be accounted for, such as \t.  I was hoping for a solution that would always match the character count displayed on screen no matter what was entered into the RadEditor content box.



0
Princy
Top achievements
Rank 2
answered on 24 Feb 2014, 04:31 AM
Hi,

Please have a look into the sample code snippet which works fine at my end. The above posted code is working fine for me.

ASPX:
<telerik:RadEditor ID="RadEditor1" runat="server">
</telerik:RadEditor>
<telerik:RadButton ID="RadButton1" runat="server" Text="Get Length" OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string editortext = RadEditor1.Text;
    int count = editortext.Split('\n').Length - 1;
    int len = (RadEditor1.Text.Length) - (count * 2);
}

Thanks,
Princy.
Tags
Editor
Asked by
Education
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Education
Top achievements
Rank 1
Share this question
or