View Javadoc

1   package fr.in2p3.jsaga.helpers;
2   
3   /* ***************************************************
4    * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
5    * ***             http://cc.in2p3.fr/             ***
6    * ***************************************************
7    * File:   Strings
8    * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
9    * Date:   9 mars 2010
10   * ***************************************************
11   * Description:                                      */
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  }