简体   繁体   English

Java string.split()约定

[英]Java string.split() convention

I'm using the following line of code in my program to get the first part of a string. 我在程序中使用以下代码行来获取字符串的第一部分。

struct.trailing.split(" ")[0]

For example, the string "Dogs and cats" would return "Dogs" with this line of code. 例如,字符串“ Dogs and cats”将使用此行代码返回“ Dogs”。 Is what I wrote convention? 是我写的约定吗? I tried this at random and it worked, piquing my curiosity, 我随意地尝试了一下,并且很好地激发了我的好奇心,

StringTokenizer also can be used StringTokenizer也可以使用
StringTokenizer st2 = new StringTokenizer(str, " ");
do the same. 照着做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM