EN
Java - split string by hyphen sign (minus sign - ascii 45 code)
3 points
In this article, we would like to show you how to split string by hyphen sign in Java.
Practical example:
xxxxxxxxxx
1
public class Program {
2
3
public static void main(String[] args) {
4
5
String text = "some-example-text";
6
String[] parts = text.split("-");
7
8
System.out.println(parts[0]); // some
9
System.out.println(parts[1]); // example
10
System.out.println(parts[2]); // text
11
}
12
}
Output:
xxxxxxxxxx
1
some
2
example
3
text