简体   繁体   English

用选项卡拆分Java字符串

[英]Java string split with tabs

Given that string is a String , what does string.split("[\\t]"); 给定stringStringstring.split("[\\t]"); do? 做? I don't understand what the brackets are for. 我不明白括号的用途。 Thanks! 谢谢!

string.split("[\\t]"); will split the string into an array of strings with a Tab being the separating character. 会将字符串拆分为字符串数组,其中Tab为分隔符。 The brackets are for defining a construct regex pattern or a character class, and with only one character they're actually not needed. 括号用于定义构造正则表达式模式或字符类,实际上仅不需要一个字符。 Here is an example 是一个例子

It is the same as string.split("\\\\t"); 它与string.split("\\\\t");相同string.split("\\\\t"); but I guess some people find it easier to read. 但我想有些人会觉得它更容易阅读。

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

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