Char-to-String conversion



  • Real code in production (pstmt is a Java prepared statement):

    pstmt.setString(10,""+'S');
    


  • Yeah, it should be

    pstmt.setString(10, String.copyValueOf( new char[ ]{ 'S' } );

    Much better performance.

    Edit: so the forum wtfware doesn't like two brackets with no space. Go figure...



  • how about

    [code]StringBuffer temp = new StringBuffer();

    temp.append('S'); 

    pstmt.setString(10, temp.toString());

    [/code] Oh, wait...



  • I would think that the javac could figure out what that resolves to and just optimize away the stupidity....

     



  • @snoofle said:

    I would think that the javac could figure out what that resolves to and just optimize away the stupidity....
    It should, but that doesn't make it any less stupid.



  • @TheRider said:

    how about

    <font face="Lucida Console" size="2">StringBuffer
    temp = new
    StringBuffer();</p><p>temp.append('S');&nbsp;</p><p>pstmt.setString(10,
    temp.toString());</p><p></font> Oh, wait...

     

    Nah, I don't think the mixed HTML and Java programming style is likely to catch on any time soon. 



  • Can this be made into a Web service? You pass it a character, and it returns the string?



  • @rbowes said:

    Can this be made into a Web service? You pass it a character, and it returns the string?

     

    Only if the webservice dips into a database which has a hard-coded mapping of character-to-string conversions, differentiated only by JDBC datatype. Oh, and the datacenter with the database should be located in New Guinea.

     

     



  • Come up with two XML schemas: one with a char and one with a string, then make an XSLT to translate between them. 



  • "I don't think the mixed HTML and Java programming style is likely to catch on any time soon."

    You haven't seen some of the JSP pages I've had to deal with.

     



  • @Rootbeer said:

    "I don't think the mixed HTML and Java programming style is likely to catch on any time soon."

    You haven't seen some of the JSP pages I've had to deal with.

     

    The quote button is even easier to use, and we will all know exactly who you are replying to.

    You can just highlight what you want to quote and click it if you don't want the entire post.



  • @MasterPlanSoftware said:

    You can just highlight what you want to quote and click it if you don't want the entire post.

    That is the most awesome feature on this forum. It makes it so easy to break up a long entry for targeted replies.



  • @AbbydonKrafts said:

    That is the most awesome feature on this forum. It makes it so easy to break up a long entry for targeted replies.
     

    Agreed.



  • That is the only awesome feature of this forum. (though Highlight + Ctrl+I is nice too)



  •  @Zecc said:

    That is the only awesome feature of this forum. (though Highlight + Ctrl+I is nice too)

    For italics? What editor DOESN'T do that?

    Or am I missing some cool feature?



  • @AbbydonKrafts said:

    @MasterPlanSoftware said:
    You can just highlight what you want to quote and click it if you don't want the entire post.

    That is the most awesome feature on this forum. It makes it so easy to break up a long entry for targeted replies.

    Community Server needs Clippy for new users..

     
    "I see you are trying to reply to a post!  The quote button can be used to add context to your reply!  Would you like me to do this for you?"

     
    "I noticed you tried to quote the OP!  Since it is the first post in the thread anyone who will read your reply has surely read the OP!  Additionally, the primary theme for the thread has already been established by the OP, so anyone with an IQ over 80 will realize the appropriate context of your reply without having to re-read the entire first post!  Should I go ahead and de-activate your account now?"



  • @MasterPlanSoftware said:

    For italics? What editor DOESN'T do that?

    Or am I missing some cool feature?

    My
    point exactly. It's not awesome, it's expected. The quoting feature,
    now, that's something I never saw anywhere else.



  • @MasterPlanSoftware said:

    @Zecc said:

    That is the only awesome feature of this forum. (though Highlight + Ctrl+I is nice too)

    For italics? What editor DOESN'T do that?

    Not only that, but he moves his hand to his mouse and highlights to italicize, instead of doing ctrl-i before and after typing the text.  How unproductive.



  • Actually I use Shift+arrows, but thanks for the heads-up :)



  • @Zecc said:

    Actually I use Shift+arrows, but thanks for the heads-up :)

    Do not try to butter me up with your sweet, sweet lies!  You have been exposed as an inefficient typist and the only acceptable punishment is death by the smell of fresh, baking French bread!  Muhahahahahah!



  • @morbiuswilters said:

    Do not try to butter me up with your
    @morbiuswilters said:
    smell of fresh, baking French bread!

    mmmmmmm.... butter



  • @belgariontheking said:

    @morbiuswilters said:

    Do not try to butter me up with your
    @morbiuswilters said:
    smell of fresh, baking French bread!

    mmmmmmm.... butter

     

    Yeah really, good thing I had steak in the fridge for lunch. Otherwise I would be pissed. And hungry.



  • @morbiuswilters said:

    Community Server needs Clippy for new users..

    I was in the middle of taking a sip of soda when I read the last line. I almost sprayed the screen.



  • @TheRider said:

    StringBuffer temp = new StringBuffer();
    temp.append('S');
    pstmt.setString(10, temp.toString());
     



  • @Physics Phil said:

    @TheRider said:

    StringBuffer temp = new StringBuffer();
    temp.append('S');
    pstmt.setString(10, temp.toString());
     
    Thanks for formatting this. The code looks much nicer now. I always feel uncomfortable and inhibited with this forum's editor.



  • @TheRider said:

    I always feel uncomfortable and inhibited with this forum's editor.

    Be a man and use plain-text! Gain control of your data and Jam It!



  • Its not the worst mistake imaginable. ""+'S' vs "S" -- ooooooo

    Now if this is an insight into his coding style, then its a diff story.



  • @AbbydonKrafts said:

    @TheRider said:
    I always feel uncomfortable and inhibited with this forum's editor.

    Be a man and use plain-text! Gain control of your data and Jam It!

     

    I hate "gain control" statements. It just means "do it manually" and I don't want to. :P What control do you gain from doing it manually? Just the backspace working!



  • @dlikhten said:

    What control do you gain from doing it manually? Just the backspace working!

    Can you do <font face="Courier New, Courier">inline fixed-width text</font> with the WISYWIG editor? I remember switching from it because of that. It also b0rks the image insertion (width=0, discussed before).



  • @Spectre said:

    It also b0rks the image insertion (width=0, discussed before).
    Not always.  If you wait for the height and width to appear in the "insert image" window, it'll insert the correct height and width for you.  Presumably, it downloads the file itself so it can populate those attributes.



  • @AbbydonKrafts said:

    That is the most awesome feature on this forum. It makes it so easy to break up a long entry for targeted replies.
     

     AIM!

     FIRE!

     

    Oh, not that kind of targetted reply. Sorry. 



  • I can't beleive I just got a real coding idea from a WTF!  I've always used +"" when my member is a char and the column is CHAR(1) because jdbc gives only setString not setChar.  But now that I'm proxying the PreparedStatement, I can add a setChar and eliminiate +"".  Sorry that this is too serious for the daily WTF but really, when do you ever get a good coding idea from a WTF?!



  • Sorry for not following the comments, but..



    Reminds me my previous WTF job (C++) where it was a popular trick to use strcpy to set a string empty. Like



    strcpy( astring, "" );



    I told my boss and senior coworkers that it would be more effective to write *astring=0 or astring[0]=0 but they didn't get it.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.