This is a snippet for me but fond that it may also be helpful to many so I wanted to take some time to place on the site. Too many times we are tasked with creating a blog and then it is needed to only show so much.
The Power Of Substring
The substring is about the easiest way of going about this as depicted here on the trusty W3C . But ironically upon my research of something I do know I found this little snippet of code as well.
Now the reason this stood out to me is just the simple fact that you can determine the amount you may want to show. So instead of only showing say 100 characters lets say you want just a little more to show to captivate the click per se.
(text_truncate(‘Super Duper Ice Cream Scooper’,19))
What the result of this would be is Super Duper Ice Cre….
Not that big of a deal as to do this with substring is just as easy too;
post.content.substring(0,90) + “…”
in this example, we are taking a variable and then just saying Yo substring from 0-90 you are good then put 3 dots on it! In this journey, I keep finding that there are literally 100 ways to get to the same result, and sometimes well most of the times taking the fastest approach is the best. I just enjoy finding ways of playing with code and this one stood out.