Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Letter from Number generator

Letter from Number generator

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nooner
    wrote on last edited by
    #1

    Hey I'm looking for a bit of help for a generic letter (see code below) Generator. The funciton takes a number and returns a String. expected: input output ----- ------ 1 a 26 z 27 aa 28 ab 52 az 53 ba 54 bb 78 bz 79 ca 702 aaa 703 aab 704 aac ... Here is the code I got so far:

        public String getLetter(int? number)
        {
            number -= 1;
            String letter = "";
            char\[\] lettersA = {
                                 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
                                 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                                 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                              };
    
            int size = number.Value % 26;
            int bigSize = number.Value % 676;
            int loop = (int)Math.Floor((decimal)(number.Value / 26));
            int bigLoop = (int)Math.Floor((decimal)(number.Value / 676));
    
    
            for (int i = 0; i < loop; i++)
            {
                letter += lettersA\[i\];
            }
            letter += lettersA\[size\];
    
            return letter;
        }
    

    Please respond if you have a solution. Thank you, Marc

    Life is too short to program in Visual Basic.

    C 1 Reply Last reply
    0
    • N Nooner

      Hey I'm looking for a bit of help for a generic letter (see code below) Generator. The funciton takes a number and returns a String. expected: input output ----- ------ 1 a 26 z 27 aa 28 ab 52 az 53 ba 54 bb 78 bz 79 ca 702 aaa 703 aab 704 aac ... Here is the code I got so far:

          public String getLetter(int? number)
          {
              number -= 1;
              String letter = "";
              char\[\] lettersA = {
                                   'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
                                   'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                                   's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                                };
      
              int size = number.Value % 26;
              int bigSize = number.Value % 676;
              int loop = (int)Math.Floor((decimal)(number.Value / 26));
              int bigLoop = (int)Math.Floor((decimal)(number.Value / 676));
      
      
              for (int i = 0; i < loop; i++)
              {
                  letter += lettersA\[i\];
              }
              letter += lettersA\[size\];
      
              return letter;
          }
      

      Please respond if you have a solution. Thank you, Marc

      Life is too short to program in Visual Basic.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why take an int? What happens if you get null passed in ? You don't check for it. What is going wrong right now ? It's hard to 'find a solution' if you don't tell us what the problem is. I can see why this probably can never work, your for loop can't possibly return any thing but a, ab, abc, etc. I would expect to use a while loop and a stringbuilder to build a string based on the values I kept subtracting from the core number until I got to 0.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      N 1 Reply Last reply
      0
      • C Christian Graus

        Why take an int? What happens if you get null passed in ? You don't check for it. What is going wrong right now ? It's hard to 'find a solution' if you don't tell us what the problem is. I can see why this probably can never work, your for loop can't possibly return any thing but a, ab, abc, etc. I would expect to use a while loop and a stringbuilder to build a string based on the values I kept subtracting from the core number until I got to 0.

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        N Offline
        N Offline
        Nooner
        wrote on last edited by
        #3

        ok I'll try and add a StringBuilder to this. I spent a day on it and the solution was not cliquing. I think I'll just get out an algorithms book and start from square one. :doh: Thanks, Marc

        Life is too short to program in Visual Basic.

        C 1 Reply Last reply
        0
        • N Nooner

          ok I'll try and add a StringBuilder to this. I spent a day on it and the solution was not cliquing. I think I'll just get out an algorithms book and start from square one. :doh: Thanks, Marc

          Life is too short to program in Visual Basic.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I think your best bet is to set a breakpoint and step through and see what your code is doing, so you can see where it's deviating from your intentions.

          Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups