Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm new to this, so please understand me;/

I'm creating an app in appery.io and it has to count the number of letters of text inserted by the app user(without spaces).

I have an input field created(input), a button to press and show the result in a label(result)

the code for the button:

var myString = getElementById("input");

var length = myString.length;

Apperyio('result').text(length);

Can you please tell me what is wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
96 views
Welcome To Ask or Share your Answers For Others

1 Answer

To ignore a literal space, you can use regex with a space:

// get the string
let myString = getElementById("input").value;

// use / /g to remove all spaces from the string
let remText = myString.replace(/ /g, "");

// get the length of the string after removal
let length = remText.length;

To ignore all white space(new lines, spaces, tabs) use the s quantifier:

// get the string
let myString = getElementById("input").value;

// use the s quantifier to remove all white space
let remText = myString.replace(/s/g, "")

// get the length of the string after removal
let length = remText.length;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...