如何获取JTextArea中的字符数? [英] How to get the number of character in a 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屋!