Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code generation help

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... so what have you tried so far? What part of this is hard for you?
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it ok I've figured it out

I had to change

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


temp = temp.replaceAll("\"", "");
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"):
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob for knocking some sense into me there!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic