This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Code generation help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Code generation help" Watch "Code generation help" New topic
Author

Code generation help

Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

I have a cv file which looks like this

I want to process the strings so that I get an output similar to this






Can someone suggest a simple String code to make "3D Objects " turn into "3dobjects"=>"3D Objects",

many thanks
[ November 07, 2007: Message edited by: Nikos Katsikanis ]

Jesus lives
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

... so what have you tried so far? What part of this is hard for you?


[Jess in Action][AskingGoodQuestions]
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Hi there again

This is my code so far



in this part of the code it is failing to remove the quotes from the .csv file



also this code never evaluates to true



[ November 07, 2007: Message edited by: Nikos Katsikanis ]
[ November 07, 2007: Message edited by: Nikos Katsikanis ]
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

it ok I've figured it out

I had to change

temp.replaceAll("\"", "");
to


temp = temp.replaceAll("\"", "");
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Sorry Guys I should have tried harder before posting. I just felt lazy when it come to working with Strings and was wanting one of yo guys to do the work. Please forgive me.


I created the working code and its here



From

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20


I don't really get this. Why catch the NullPointerException? There is nothing there that could throw one. Not the creation of the file, the FileReader or the BufferedReader. Not the call to br.readLine(), data[count] or data.length. So what will throw it? Nothing, as far as I can see it.

The same goes for the ArrayIndexOutOfBoundsException. You make sure that data starts at 0, and you exit the loop as soon as it becomes too large for the array. So again, nothing could throw it.


Furthermore, you do know that br.readLine() will return null only when there is nothing more to be read? So if this occurs, the remainder of the array will be filled with "empty". If you want this, you could just as well break when it is null and use java.util.Arrays.fill(data, count, data.length, "empty"):


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

Thanks Rob for knocking some sense into me there!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code generation help