---
title: "Strul med datum och array."
type: "forum-thread"
url: "https://www.webforum.nu/amne/java/53293-strul-med-datum-och-array"
topic: "Java"
topic_url: "https://www.webforum.nu/amne/java"
author: "AG"
published: "2002-09-15T16:50:09.000Z"
updated: "2002-09-15T16:50:09.000Z"
replies: 0
views: 238
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/java/53293-strul-med-datum-och-array"
---

# Strul med datum och array.

## #1 — AG, 2002-09-15T16:50Z

Har lite krux med följande:

```
'Error
Note: sun.tools.javac.Main has been deprecated./sunjava.jsp:57: ')' expected.List convertTheEvents( List theListOfEvents )                           ^/sunjava.jsp:100: Missing term.{ ^/sunjava.jsp:100: '}' expected.{ ^/sunjava.jsp:111: 'try' without 'catch' or 'finally'.}^/sunjava.jsp:115: Identifier expected.      pageContext.write(_jsp_string1, 0, _jsp_string1.length);                                    
^5 errors, 1 warning

'Koden
Vector vector = new Vector();
try {
     BufferedReader bufferedReader = new BufferedReader( new StringReader( input ) );
     String string = "";

     while( ( string = bufferedReader.readLine() ) != null )
          vector.addElement( string );
}
catch( IOException e ) {
     // Kunde inte läsa
}

Object[] arrayen = vector.toArray();
      
Pattern DAY_DATE_PATTERN = Pattern.compile( "\\p{Alpha}+ (.*)" );
Pattern TIME_PATTERN = Pattern.compile( "\\d" );   
List convertTheEvents( List theListOfEvents )
{
Matcher dm = DAY_DATE_PATTERN.matcher("");      
Matcher tm = TIME_PATTERN.matcher("");      
String currentDate = "";      
String nextItem; 
for ( ListIterator iter = events.listIterator(); iter.hasNext();  )      
{      
         
nextItem = (String)iter.next();         
// Let's find out if it is the dayDate format..         
dm.reset( nextItem );         
if ( dm.lookingAt() )         
{            
// then you found it...and YY-MM-DD is captured in group 1            
currentDate = dm.group( 1 );            
// get rid of it inside the list...you have the info you needed.            
iter.remove();         
}         
else         
{            
// It must be the other kind (the time pattern).            
tm.reset( nextItem );            
if ( tm.lookingAt() ) 
// then you need to replace it                                  
// with the correct format.            
{               
iter.set( currentDate + ' ' + nextItem );            
}            
else            
{               
// what the heck went on here???               
System.out.println( "error in format: " + nextItem );            
}         
}      
}      
// now all the stuff in your List has the correct format.      
// Do whatever you wanted to do with them.      
return events;   
}   
// Here it is in action   
{     
String [] events = 
{
for(int i = 0; i < arrayen.length; i++) {
out.println(arrayen[i]);
}
};      
List better = convertTheEvents( Arrays.asList(events) );      
for ( Iterator iter = better.iterator(); iter.hasNext(); )      
{         
System.out.println( iter.next() );      
}   
}
```

Har försökt klippa ut de rätta delarna från, som fungerar lysande. 
<http://test.myserverspy.com/test/help.txt>

Men som sagt det är strul

Andreas

Permalänk: https://www.webforum.nu/p/53293

---

Tråden på webben: https://www.webforum.nu/amne/java/53293-strul-med-datum-och-array
