Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: How to get the next char in the abc  (Read 4323 times)

0 Members and 1 Guest are viewing this topic.

lacosaweb

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 116
    • View Profile
How to get the next char in the abc
« on: July 30, 2009, 05:48:29 PM »

Hi, are any method to get the next letter in the alphabet?

I try

string="a";
string=string+1;

The result is "a1" I need "b" as a result.

Any idea? Thanks.
Logged

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How to get the next char in the abc
« Reply #1 on: July 30, 2009, 09:00:45 PM »

I am experimenting with Arrays right now and you could use Arrays for this too. I'm just not sure it's very practical for whatever it is you try to achieve, but this is how it would work:

Code: [Select]
var Alphabet = new Array("a", "b", "c", "d", "e");
Game.Msg( Alphabet[0+2] );

So what you basicly do is fill an array with all the characters as values, and where ever you need it you return the Array value by its key. In this case it would return c (Array Keys always start with 0, so "a" is 0).

As said, I'm not sure its practical for you.
« Last Edit: July 30, 2009, 09:02:33 PM by Darky »
Logged

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re: How to get the next char in the abc
« Reply #2 on: July 30, 2009, 09:19:47 PM »

You can use this function:

Code: [Select]
function GetNextLetter(alphabet, letter)
{
   var i=0;
   var nextLetter = "";

   for(i=0; i<alphabet.Length; i=i+1)
   {
if(alphabet[i] == letter)
{
   if(i+1 < alphabet.Length) nextLetter = alphabet[i+1];
   else nextLetter = "z";
}
   }

   return nextLetter;

}

And here you have several examples of use:

Code: [Select]
/* Example of use: */

var alphabet = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z");
var letter = "k";

Game.Msg(GetNextLetter(alphabet, letter)); /* It should show l */
Game.Msg(GetNextLetter(alphabet, "b"));    /* It should show c */

var other_letter = GetNextLetter(alphabet, "y");   /* other_letter should have z */

I hope this helps you!  ;)
Logged

lacosaweb

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 116
    • View Profile
Re: How to get the next char in the abc
« Reply #3 on: July 31, 2009, 03:50:25 PM »

Thanks for all you responses. I found another method to do this:

Code: [Select]
function Sumaletra(char)
{
var abc = new String("abcdefghijklmnopqrst");
var posicion;
posicion=abc.IndexOf(char);
char=abc.Substr(posicion+1,1);
return char;
}
Logged

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re: How to get the next char in the abc
« Reply #4 on: July 31, 2009, 06:24:51 PM »

Yes as you can see there are several aproachs to this solution  ;)
Logged
 

Page created in 0.017 seconds with 20 queries.