Jeg har denne kode:
    private int NumberOf(String Text, String Splitter) {
    int Number = -0;
        
        for (int i=0;i<Text.length();i++)  {
            if (Text.substring(i,i+1) == Splitter) {
                Number = Number + 1;
            }
        }
    
    return Number;
    }
    
    private void StringToArray(String AllSections, String[] SectionArray) { 
    String CopyAllSections = AllSections;
    
    for (int i=0;i<NumberOf(AllSections,"^");i++) {
        if (i == 0) {
            if (NumberOf(AllSections,"^") == 0) {
                SectionArray[0] = CopyAllSections;
            } else {
                SectionArray[0] = CopyAllSections.substring(1, CopyAllSections.indexOf("^"));
                CopyAllSections = CopyAllSections.substring(SectionArray[0].length()+1, CopyAllSections.length());
            }
        } else {
            if (i == NumberOf(AllSections, "^")) {
                SectionArray[i] = CopyAllSections;                
            } else {
                SectionArray[i] = CopyAllSections.substring(1, CopyAllSections.indexOf("^"));
                CopyAllSections = CopyAllSections.substring(SectionArray[i].length()+1, CopyAllSections.length());            
            }
        }
    }
    
    }
Hvor NumberOf gerne skulle retunere antallet af et bestemt tegn i en streng, og StringToArray skulle gerne splittes op ved ^´erne og ligge delene i et array
Men der er fejl, eller ikke fejl men det virker ihvertfald ikke... Nogen der kan se problemet?
Man bruger koden ved at skrive:
        String[] txtSectionArray = new String[5];
        String txtFullString = "hej^hej2^hej3^hej4^hej5";
        StringToArray(txtFullString, txtSectionArray);
mvh.
Lasse Espeholt
www.mobileservices.dk - en del af hverdagen
[Redigeret d. 22/05-03 17:43:30 af Lasse Espeholt]