...

View Full Version : String Literals and Problems



redwood_player
01-11-2007, 09:44 PM
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

david_kw
01-11-2007, 09:54 PM
You can use Array.reverse() for an array but I'm not aware of one for string.

david_kw

david_kw
01-11-2007, 09:57 PM
Of course you could do this. :)



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


or



var s = "Here it is";
alert(s.split("").reverse().join(""));


david_kw

Brandoe85
01-11-2007, 09:58 PM
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.

redwood_player
01-11-2007, 11:26 PM
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

redwood_player
01-11-2007, 11:28 PM
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?

david_kw
01-11-2007, 11:43 PM
Heh, that is java code not javascript. You accidently posted in the wrong forum so I doubt any of our solutions worked. :)

david_kw

redwood_player
01-12-2007, 01:11 AM
I was wondering why everything looked so different. Hahaha



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum