I'm looking to split a string at the first ':', to prevent issues if the second part of the string contains a ':'. I've been looking at Regexes, but am still having some issues, can somebody give me a hand?
Thanks.
-
3Could you include an example of expected input and output?FThompson– FThompson2012-12-01 21:29:43 +00:00Commented Dec 1, 2012 at 21:29
Add a comment
|
3 Answers
You can use the overload of split that takes a limit parameter:
String[] result = s.split(":", 2);
Comments
You can use 2 argument String#split to specify the number of elements you want in your array obtained after split: -
String str = "rohit:jain:use:single:split";
String[] arr = str.split(":", 2);