how to get string length code example

Example 1: length of string java

public class Sample_String {
    public static void main(String[] args) {
        //declare the String as an object S1 S2
        String S1 = "Hello Java String Method";
        String S2 = "RockStar";

        //length() method of String returns the length of a String S1.
        int length = S1.length();
        System.out.println("Length of a String is: " + length);
        //8 Length of a String RockStar
        System.out.println("Length of a String is: " + S2.length());
    }
}

Example 2: length of string in java

str.length();

Example 3: how to check how many strings are in a sentence javascript

function WordCounter (str) {
	var words = str.split(" ").length;
	return words;
}
// this should work!

Example 4: java length of string

string.length()

Example 5: compare string length javascript

const s1 = 'javascript';
const s2 = 'node.js';

console.log(s1.length > s2.length); // true

Example 6: How to get length of string in javascript without using native length method

var str = userInput[0];
  var count = 0;
  while(str[count] !== undefined)
  {
      count += 1;
  }
  console.log(count)

Tags:

Php Example