我想使用“”拆分字符串,但是int main()
{
struct details *student = details_pointer(n);
.. do stuff
free(student);
}
给我数组中的空字符串,这是我不想要的。
我尝试过:
.split()
输出:
[“”,“”,“”,“”,“”,“你好”,等等。...
预期输出:
[“ hello”,“ world!”,“ b”,“ y”,“ e”]
我该如何实现?
首先,修剪字符串,然后用一个或多个空格(\s+
)分割。
String string = " hello world! b y e ";
String[] arr = string.trim().split("\\s+");
// output: ["hello","world!","b","y","e"]