JavaScript Algorithm Question: String Length

JavaScript Algorithm Question: String Length

Given a non-empty string whose length does not exceed 100, please find its specific length.

input format

Enter a line, representing a string. Note that the string may contain spaces.

output format

Output an integer representing its length.

data range

1≤string length≤100
There is no carriage return at the end of the string

Input sample:

I love Beijing.

Sample output:

15
let buf = "";

process.stdin.on("readable", function() {
    
    
    let chunk = process.stdin.read();
    if (chunk) buf += chunk.toString();
});

process.stdin.on("end", function() {
    
    
    let str = buf.split('\n')[0];  // 如果行末有回车,则去掉行末的回车
    console.log(str.length);
});

Guess you like

Origin blog.csdn.net/qq_42465670/article/details/130516738