length of strings | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

length of strings

How do you find the length of strings? I am trying to write a project where to activate the if else statement, you have to type your name, and depending on the length of your name, you get a response. The only problem is I don't know how to find the length of stings. Can anyone please help me?

12th Jun 2017, 10:28 PM
Cassie Scheidt
Cassie Scheidt - avatar
5 Answers
+ 5
Actually Ben, in Java to get string length you use length() with parenthesis. I threw together a code. run it and it will give you the length. remove the parenthesis and it will give you an error. Cassie didn't specify language, but her profile says she is learning Java. https://code.sololearn.com/cMJ5YgyNfldp/?ref=app
12th Jun 2017, 10:54 PM
LordHill
LordHill - avatar
+ 3
@Justin Hill 👍👍
13th Jun 2017, 8:03 AM
Benneth Yankey
Benneth Yankey - avatar
+ 2
In JS length it's a property. So for strings its, string.length Eg: if (string.length < 6) { // code here } else { // code here }
12th Jun 2017, 10:33 PM
Benneth Yankey
Benneth Yankey - avatar
+ 2
str.length()
12th Jun 2017, 10:39 PM
LordHill
LordHill - avatar
0
alert("msg").length
17th Jun 2017, 10:31 AM
Рома
Рома - avatar