Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation String Literals and Problems

    Hi Everyone,

    Is there any way to reverse a string literal to repeat exactly what was input except in reverse? Or is this just a pipe dream? If anyone knows any sites I could go to to research this topic or could assist me with this I would be grateful.

    Regards,

    redwood

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use Array.reverse() for an array but I'm not aware of one for string.

    david_kw

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Of course you could do this. :)

    Code:
        var s = "Here it is";
        var a = s.split("");
        var r = a.reverse();
        var j = a.join("");
        alert(j);
    or

    Code:
        var s = "Here it is";
        alert(s.split("").reverse().join(""));
    david_kw
    Last edited by david_kw; 01-11-2007 at 09:20 PM. Reason: added shorter version

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Loop through the string backwards and put together the new string in reverse.

    Substring should do the trick:
    http://www.w3schools.com/jsref/jsref_substring.asp

    good luck.

  • #5
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    While Loop

    Hi all,

    I found a new code to reverse the string (I used StringBuilder), and now my program is almost complete, except now Im having one last problem. Before, I had no problem with my while loop, but now when I put it in the code (at the input area for the scanner), it has problems compiling. I have pasted the code below, please give me your opinion. (I have included my code as a text attachment)

    Regards,

    Redwood
    Attached Files Attached Files

  • #6
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh never mind, I just moved the StringBuilder code above the while statement and it works now. But look at my code and tell me what you think. Is this good or no?

  • #7
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh, that is java code not javascript. You accidently posted in the wrong forum so I doubt any of our solutions worked. :)

    david_kw

  • #8
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was wondering why everything looked so different. Hahaha


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •