gpt4 book ai didi

java - 如何在输入文本字段之间放置空格

转载 作者:行者123 更新时间:2023-12-01 23:28:36 25 4
gpt4 key购买 nike

我试图在文本字段中输入的数字之间放置空格。我正在使用以下代码:

    for(int i = 0; i <= 2; i++)
{
char cijfer = tf1.getText().charAt(i);
char getal1 = tf1.getText().charAt(0);
char getal2 = tf1.getText().charAt(1);
char getal3 = tf1.getText().charAt(2);
}

String uitvoerGetal = getal1 + " " + getal2 + " " + getal3;

我想我还不理解 charAt() 函数,是否有人有一个链接以某种方式解释它,以便我也可以完成这项工作?提前致谢!

最佳答案

示例:

public class Test {

public static void main(String args[]) {
String s = "Strings are immutable";
char result = s.charAt(8);
System.out.println(result);
}
}

这会产生以下结果:

a

更多详细信息来自 java 文档

public char charAt(int index)

Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Specified by:
charAt in interface CharSequence
Parameters:
index - the index of the char value.
Returns:
the char value at the specified index of this string. The first char value is at index 0.
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.

关于java - 如何在输入文本字段之间放置空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19653691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com