ASP Script Function to cut sentences exactly by words not by characters
ASP Function ini berguna untuk memotong text content (kalimat) per kata bukan per huruf untuk mencegah kata yang tidak lengkap (incomplete word) karena terpotong di tengah kata (beberapa huruf ilang karena pemotongan per huruf).
Sangat sering kita ingin menampilkan list/daftar content beserta penjelasan singkat tentang topik yang dimaksud. tetapi kita ingin membatasi description itu tidak terlalu panjang (untuk membuat penasaran a.k.a meningkatkan pageviews & penyesuaian terhadap design), Tetapi kalau kita menggunakan String Operations Left(), Right(), Mid() Kombinasi dengan Len() terkadang pemotongan tidak tepat di kata terakhir karena kebentur spesifik length sehingga memungkinkan ada kata (lebih tepatnya kombinasi karakter) yang tidak lengkap dan tidak puny arti (meaningless).
Contoh:
ASP Tutorial
Tutorial For Classic ASP programmer Provides tons of ar…
Dengan menggunakan fungsi cutWords ini hal tersebut bisa di cegah sehingga deescription bisa di optimize menjadi
ASP Tutorial
Tutorial For Classic ASP programmer Provides tons of …
Atau
ASP Tutorial
Tutorial For Classic ASP programmer Provides tons of articles…
ASP SCRIPT SOURCE
If Len(sFullText) > nLong Then
sReturn = “”
aCountWords = Split(sFullText, ” “)
For Each iTemp In aCountWords
If Len(sReturn) <= nLong Then
if len(sReturn)>0 Then sReturn = sReturn & ” “
sReturn = sReturn & iTemp
End If
Next
Erase aCountWords:Set aCountWords=Nothing
CutWords = sReturn & sAddWord
Else
CutWords = sFullText
End If
End Function
Function Parameters
- sFullText = Kalimat Asli/Original yang belum di cut off
- nLong = Panjang Character Maximum (Allowed Characters)
- sAddWord = Indicator Cutting, Kata atau kombinasi kata/huruf yang ditaur dibelakang sebagai indikator bahwa kalimat tersebut dipotong (optional)


















thanks that was good.
be aware some people! when i copy & paste your script, the double quotes turn into weird characters, like beginning quote and ending quote, because of your CMS system. But no problem, i just do search & replace, it work well thank you.
so it takes your input text, splits it by space, then puts each word into an array, goes through the array and adds each word together again, making sure it is not getting over the length limit.
than you for sharing. wishes well for you!
gr8 i wrote it in indonesian language and glad you can understand how it works
thank you