• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replace not working when trying to change filename

 
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to read each character of a filename, camel case the letters and then remove the spaces and underscores. Could you please tell me what I'm doing wrong...


Thanks in advance
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you reading each character to do a replace? You can do it with one regular expression:



Now if you want to do the camel Case it would be




Eric
 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric,
My reason for reading each character was for the capitalization, not necessarily for the spaces and underscores. I see that your example works, but what is the value of 'match' when you pass it into the function? Thanks again.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let the code tell you:


Eric
 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that, I just outputted it to the console and saw that it was the first letter after the space or underscore. I guess I should have thought of that before I asked. Do you mind if I ask why or how it works like that?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second parameter is an anonymous function. [unanamed funciton]

It could be a named one too.



JavaScript looks at the 2nd parameter and says what do I have here? I have a string, I will just insert that in. In our case it says I have a function. I will pass in whatever I matched to it as an argument and will use whatever it returns back and use that.

JavaScript is powerful when you learn about these things!

Eric
 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that makes sense. I didn't really want to use the code you showed me without understanding what was going on.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Brrown wrote:I didn't really want to use the code you showed me without understanding what was going on.


Bravo!
reply
    Bookmark Topic Watch Topic
  • New Topic