Count characters in a field

Duncan Koza asked on March 4, 2020 03:59

I have a field called 'description' on my structured pages in Kentico 11 and I want to count the number of characters in the string.

I tried something like this but it didn't work. Any ideas?

{% If (description.count=>60) { "description is equal to or greater than 60" } else { "description is less than 60" } %}

Correct Answer

Juraj Ondrus answered on March 4, 2020 06:38

You need to use length - like {%FieldName.Length%} - just keep in mind that it also counts HTML tags, so maybe you want to strip HTML from the field's value first.

2 votesVote for this answer Unmark Correct answer

Recent Answers


Duncan Koza answered on March 6, 2020 00:17

Perfect thanks.

Also how would I do the following in ascx.

if(FileName.Length>=60) {"title=\"" + FileName + "\""}

Sorry I am such a newb. Just trying to grasp this whole thing.

0 votesVote for this answer Mark as a Correct answer

Duncan Koza answered on March 11, 2020 16:09

hey everyone, the ascx variation to my the code above is:

<%# If((Eval("FileName").ToString().Length >= 60 ), true, false) %>

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.