修剪时,文本的空间很大按键月底输入 [英] Trim text- when lot of space keys are entered at end

查看:124
本文介绍了修剪时,文本的空间很大按键月底输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在可以输入原因编辑文本字段。但是,如果一个人进入的原因,所有的空间我怎么能检测到它。是否有当一个人进入的所有场所,或没有办法,我要的文本保存文本为一个简单的hiphen。我的主要问题是如何修剪在年底即将到来的处所。

I have a edit text field in which reason can be entered. But if a person enters all spaces in the reason how can I detect it. Is there a way when a person enters all spaces or nothing , i have to save the text the text as a simple "hiphen". My main question is how to trim those spaces coming at the end.

推荐答案

该方法修剪()在修剪多余的字符串空间。

The method trim() in String trims excess spaces on Strings.

String str = "Hello  ";
String str2 = str.trim();

STR2就等于你好。

str2 would equal "Hello".

至于当一个人进入的所有场所检测 - 检查str.length()你已经跑了str.trim后()

As for detecting when a person enters all spaces - check the str.length() after you've ran str.trim().

这篇关于修剪时,文本的空间很大按键月底输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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