1 package fr.in2p3.jsaga.helpers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public class Strings {
16 public static String substringBeforeFirst(String str, char separator) {
17 int pos = str.indexOf(separator);
18 if (pos > -1) {
19 return str.substring(0, pos);
20 } else {
21 return str;
22 }
23 }
24
25 public static String substringBeforeLast(String str, char separator) {
26 int pos = str.lastIndexOf(separator);
27 if (pos > -1) {
28 return str.substring(0, pos);
29 } else {
30 return str;
31 }
32 }
33
34 public static String substringAfterFirst(String str, char separator) {
35 int pos = str.indexOf(separator);
36 if (pos > -1) {
37 return str.substring(pos+1);
38 } else {
39 return str;
40 }
41 }
42
43 public static String substringAfterLast(String str, char separator) {
44 int pos = str.lastIndexOf(separator);
45 if (pos > -1) {
46 return str.substring(pos+1);
47 } else {
48 return str;
49 }
50 }
51 }