![]() ![]() If you have any better solution to truncate a string without breaking words. If length of given text is shorter then desired length then it returns whole text. It is just using regular expression to match first 50 characters with word boundary. But second code is much shorter then first code. This is useful if you have a limited space you are working with and don't want to do the alternative option, to complete the full word that was broken, which would give you mroe than 250 characters. Output of second code is same a first one. What this will do is take out the last word that gets broken apart by the truncation, this will give you less than 250 characters returned if it were to truncate right in the middle of a word.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |