Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Code generation help

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob for knocking some sense into me there!!
 
Do not set lab on fire. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic