java - String.split(".") is not splitting my long String -
i'm doing following:
string test = "this a. example"; string[] test2 = test.split("."); the problem: test2 has no items. there many . in test string.
any idea problem is?
note public string[] split(string regex) takes regex.
you need escape special char ..
use string[] test2 = test.split("\\.");
now you're telling java:
"don't take . special char ., take regular char .".
note escaping regex done \, in java, \ written \\.
as suggested in comments @oldcurmudgeon (+1), can use public static string quote(string s) "returns literal pattern string specified string":
string[] test2 = test.split(pattern.quote("."));
Comments
Post a Comment