Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / utils / StringUtils.java @ 18773

History | View | Annotate | Download (1.49 KB)

1
package org.gvsig.gpe.gml.utils;
2

    
3
import java.util.regex.Pattern;
4

    
5
public class StringUtils {
6
        //----------------------------------------------------------------------
7
        // PROBLEM WITH COMPATIBILITY OF "split()" WITH IBM J9 JAVA MICROEDITION
8
        //----------------------------------------------------------------------
9
        public static String[] splitString(String input, String sep) {
10
                return Pattern.compile(sep).split(input, 0);
11
        }
12

    
13
        public static String[] charSplit(String origin, String expresion){
14
                String ns[];
15
                String aux = origin;
16
                int indexFin;
17
                int indexStart=0;
18
                int i=0;
19
                        //take the string in couples of words separates by :
20
                indexFin = origin.indexOf(expresion);
21
                if(indexFin!=-1){
22
                        while (indexFin!=-1){
23
                                aux = aux.substring(indexFin+1);
24
                                indexFin = aux.indexOf(expresion);
25
                                i++;
26
                        }
27
                        ns = new String[i+1];
28
                        aux = origin;
29
                        i=0;
30
                        indexFin = aux.indexOf(expresion);
31
                        while (indexFin!=-1){
32
                                ns[i]= aux.substring(0,indexFin);
33
                                indexStart=indexFin+1;
34
                                aux = aux.substring(indexStart);
35
                                indexFin = aux.indexOf(expresion);
36
                                i++;
37
                        }
38
                        ns[i]=aux;        
39
                }
40
                else
41
                {
42
                        ns = new String[1];
43
                        ns[0] = origin;
44
                }
45
                return ns;
46
        }
47
        //----------------------------------
48
        // end of the split() compatibility
49
        //----------------------------------
50
        public static String replaceAllString(String original, String match_old,
51
                        String match_new) {
52
                return Pattern.compile(match_old).matcher(original).replaceAll(
53
                                match_new);
54
        }
55
}