如何获取JTextArea中的字符数? [英] How to get the number of character in a JTextArea?

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

问题描述

我有一个JTextArea,我需要将字段的每个字符转换为另一个字符. 但是为此,我需要在JTextArea中浏览.

I have a JTextArea and I need to take each one of the field's characters to translate it into another. But for this purpose I need to browse in the JTextArea.

所以我想到了一个像这样的简单循环:

So I thought of a simple loop like:

for(int i = 0; i <= t.length(); i++) { ... }

但是length()函数不合适,我找不到一个.

but the length() function is not appropriate and I can't find one which is.

如果有人已经遇到此问题,我希望对此有所帮助.

If anyone has already encountered this problem, I'd like a bit of help with it.

推荐答案

如果您需要JTextArea字段的字符串内容,请使用textArea.getText(),然后像平常一样使用该字符串,例如用length()来获取其长度.

If you need the String content of a JTextArea field just use textArea.getText(), and then use that string as you usually do, e.g. getting its length with length().

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

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