Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array of Strings problem

 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20827
68
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.split uses regular expressions, and "." has special meaning in regular expressions. Try escaping it: "\\."
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh goodness, thank you very much. It works now
 
Rob Spoor
Sheriff
Posts: 20827
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!