This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array of Strings problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array of Strings problem" Watch "Array of Strings problem" New topic
Author

Array of Strings problem

Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
Hello. I have a small problem with getting the length of an array of strings. What I want to do is write a date of the format dd.mm.yyy in a textfield, and modify it in the program in the format yyyy.mm.dd. For that, i need to process the initial data, split it into 3 strings(month, day,year) and them rearrange them in the way i want them to be. I have the following code:



What am I doing wrong?

Here is the class where i did it,maybe it helps

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

String.split uses regular expressions, and "." has special meaning in regular expressions. Try escaping it: "\\."


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

I'm not sure if it's the only problem, but I'd suggest taking a look at the definition of String.split. The argument it takes is a regular expression, and "." is a special character in regular expressions, so it needs escaping.

Edit: i.e. What Rob Said.
Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
Oh goodness, thank you very much. It works now
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array of Strings problem
 
Similar Threads
JFileChooser: Selecting multiple files error
JDesktopPane - reference JInternalFrame
Cursor handling in JTextArea
please can someone help me password my Java program!
How to communicate between one server and multiple clients