1
使用模式中的字符串分割()我有格式的輸入如何用Java
"MG3 4F W 123 TO GH2 2F E 345"
or
"MG3 4F W 123 To GH2 2F E 345"
or
"MG3 4F W 123 tO GH2 2F E 345"
or
"MG3 4F W 123 to GH2 2F E 345"
我必須分裂這種串的基礎上「TO」。下面是我試圖代碼用它來分割它使用模式,但它會給編譯錯誤,你可以幫我嗎?
public static final String DIVIDER_PATTERN = "{tT}{oO}";
public static void main(String[] args)
{
Pattern pt = Pattern.compile(DIVIDER_PATTERN);
String hello = "Hello to World TO this tO test To how";
String array[] = hello.split(DIVIDER_PATTERN);
System.out.println(array[0]);
}
對不起,我錯了添加pattern.Its [TT] [OO] – cryptonkid 2012-01-17 19:13:48
所有我們需要修改上面的代碼有點 '公共靜態無效的主要(字符串ARGS []){ 模式 PT = Pattern.compile(」 [TT] [OO]「); String hello =「Hello to World TO this tO test To how」; 字符串數組[] = pt.split(hello); (int i = 0; i
cryptonkid
2012-01-17 19:24:52