Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • umbracocool 108 posts 197 karma points
    Apr 17, 2012 @ 21:53
    umbracocool
    0

    Count the number of characters of text in XSLT

    I would like to know how to count the number of characters of text in XSLT. Thank you very much!

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 17, 2012 @ 21:55
    Fuji Kusaka
    0

    Hi,

    You want to count umber of characters or display a certain amount of characters with xslt?

    //fuji

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 17, 2012 @ 22:05
    Lee Kelleher
    2

    To find out the number of characters in text, you can use the "string-length" function.

    <xsl:value-of select="string-length(propertyAlias)" />

    Where 'propertyAlias' is the name of your property.

    Cheers, Lee.

  • umbracocool 108 posts 197 karma points
    Apr 17, 2012 @ 22:18
    umbracocool
    0

    Thank you very much brother! Can you give me your email, so we can contact you?But is very annoying, I'd appreciate it a lot, thanks again!

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 17, 2012 @ 22:32
    Lee Kelleher
    0

    My inbox is always open... http://j.mp/leeeeee

  • Niklas Hjelm 104 posts 125 karma points
    Oct 02, 2014 @ 12:24
    Niklas Hjelm
    0

    Hi, how would you go about doing this in Razor? I wan't to count the words in my bodyText and display it so visitors can see how long the text is. Thanks

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Oct 02, 2014 @ 12:49
    Lee Kelleher
    1

    Hi Niklas,

    Did you want a character count, or a word count?

    For character count, it a simple string length:

    @Model.Content.GetPropertyValue("bodyText").Length
    

    For a word count, you'd need to define the word boundaries. A quick and dirty would be to split the string by spaces, then count the items:

    @Model.Content.GetPropertyValue("bodyText").Split(' ').Count()
    

    For more advanced techniques, check this link: http://www.dotnetperls.com/word-count

    Cheers,
    - Lee

  • Niklas Hjelm 104 posts 125 karma points
    Oct 02, 2014 @ 13:43
    Niklas Hjelm
    0

    Great, thanks Lee!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies