How to extract substring from string and length of a string?
Asked
Active
Viewed 169 times
2 Answers
1
Well you can use the MDN website to search for those but here is what you asked for :
extract substring from string
The substring()
method returns the part of the string
between the start and end indexes, or to the end of the string.
const str = 'Stephano';
console.log(str.substring(1, 3));
// "te"
console.log(str.substring(2));
// "ephano"
length of a string
The length
property of a String
object contains the length of the string :
let string = "This is text !"
console.log(string.length)
// 14

Staxlinou
- 1,351
- 1
- 5
- 20
-
thank you!! This is my code that doesn’t work function cat(ma) { l= ma.lenght return l; } – Stefano Piccioli Oct 03 '21 at 11:57
-
The function works? The problem isn't on the function itself but on how you use it. Try `cat('Test')` – Staxlinou Oct 03 '21 at 17:54
1
This is the file with the example functions. Now it works, thanks to the valuable advice
https://docs.google.com/spreadsheets/d/12jX8aAH5pkUYHFduBT8ueaebymcrACX0gdqBf5Xyl48/edit?usp=sharing
function cat(ma)
{
ll = ma.length;
return ll;
}
function tr(m)
{
lll = m.substring(2,9);
return lll;
}

Stefano Piccioli
- 19
- 4