console.log(text_truncate('We are doing JS string exercises.'))
console.log(text_truncate('We are doing JS string exercises.',19,'...'))
console.log(text_truncate('We are doing JS string exercises.',15,'!!'))
function text_truncate(str,pos,ch)
{
var temp= str.split('');
var ar = [];
var ch;
for(var i = 0; i<temp.length ; i++)
{
ar.push(temp[i]);
if(pos == null && ch == null)
{
return temp.join('');
}
else if(i == pos )
{
ar.push(ch);
break
}
}
return ar.join('');
}
To embed this program on your website, copy the following code and paste it into your website's HTML: