如何计算没有空格的字符数? [英] How to count the number of characters without spaces?

查看:145
本文介绍了如何计算没有空格的字符数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,所以请理解我; /

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

我在appery.io中创建一个应用程序,它必须计算字母数app用户插入的文本(不含空格)。

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)

按钮的代码:

var myString = getElementById("input");

var length = myString.length;

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

你能告诉我出了什么问题吗?

Can you please tell me what is wrong?

推荐答案

要忽略所有空格(新行,空格,制表符),请使用\s quantier:

To ignore all whitespace(new lines, spaces, tabs) use the \s quantifier:

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

// use the \s quanitifier to remove all whitespace
// then retrieve the length
var length = myString.replace(/\s/g, "").length;

这篇关于如何计算没有空格的字符数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆