jumlah substring dalam string
/*
It depends on how you split string and what language you use.
eg. If by substring you mean:
*/
"random string".subString(2, 5);
/*
One string/char[] will be returned *always*.
but if by substring you actually mean splitting:
*/
"random string hello r ".split(' ');
/*
An array of string/charr[][] will be returned.
- then what you can do is trim the string
- split it by any delimiter
- remove all empty strings(or just disclude them but if you plan to proccess them the former method is best)
- get the array langth property(or if you decided not to delete iterate through the array and ignore all string = "")
kind of like this:
*/
//trim and split
var temp = prompt("Enter something").trim().split(" ");
//remove all elements = ""
for(let i = 0; i < temp.length; i++) {
if(temp[i] == "")
temp.splice(i,1);
}
alert(temp.length);
//(this is a general structure and be modified to any language but I ran it as a js script)
MightyK24