hello i am supposed to display the ascii character set from 32 to 100 and then from 225-250. I have found the code to show 32 to 100 but cannot think of how to put 225 to 250 in there as well. here is my code. I just need to add an additional string of the ascii character set from 225 to 250 underneath it.

using System;

namespace hexbox
{
   class Program
   {
      public static void Main(string[] args)
      {
        Console.Write(" Dec Char  Hex\n -------------\n");
        int min = 032;
        int max = 100;
         for ( int i = min; i < max; i++ )
         {
            // get ascii character
            char c = (char) i;

            // get display string
            string display = string.Empty;

            if (char.IsWhiteSpace(c))
            {
               display = c.ToString();
            }
            else if (char.IsControl(c))
            {
               display = "control";
            }
            else
            {
               display = c.ToString();
            }
            // write table row
            Console.Write(string.Format("{0: 000}{1, 3}{0, 6:X2}\n", i, display));
         }
      }// end Main
   }// end class
}// end namespace

Try something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace daniweb
{
  public static class DisplayPairs
  {
    private class IntegerPair
    {
      private int _min;
      private int _max;
      public int Min { get { return _min; } }
      public int Max { get { return _max; } }
      private IntegerPair() { }
      public IntegerPair(int Min, int Max)
        : this()
      {
        this._min = Min;
        this._max = Max;
      }
    }
    private static string GetDisplayString(char c)
    {
      if (char.IsWhiteSpace(c))
        return c.ToString();
      else if (char.IsControl(c))
        return "control";
      else
        return c.ToString();
    }

    public static void RunTheProgram()
    {
      //from 32 to 100 and then from 225-250
      List<IntegerPair> lst = new List<IntegerPair>();
      lst.Add(new IntegerPair(32, 100));
      lst.Add(new IntegerPair(225, 250));
      foreach (IntegerPair ip in lst)
      {
        for (int i = ip.Min; i <= ip.Max; i++)
        {
          char c = (char)i;
          string display = GetDisplayString(c);
          Console.Write(string.Format("{0: 000}{1, 3}{0, 6:X2}\n", i, display));
        }
      }
    }
  }
}

Calling it:

private void button3_Click(object sender, EventArgs e)
    {
      DisplayPairs.RunTheProgram();
    }

Results in:

032       20
 033  !    21
 034  "    22
 035  #    23
 036  $    24
 037  %    25
 038  &    26
 039  '    27
 040  (    28
 041  )    29
 042  *    2A
 043  +    2B
 044  ,    2C
 045  -    2D
 046  .    2E
 047  /    2F
 048  0    30
 049  1    31
 050  2    32
 051  3    33
 052  4    34
 053  5    35
 054  6    36
 055  7    37
 056  8    38
 057  9    39
 058  :    3A
 059  ;    3B
 060  <    3C
 061  =    3D
 062  >    3E
 063  ?    3F
 064  @    40
 065  A    41
 066  B    42
 067  C    43
 068  D    44
 069  E    45
 070  F    46
 071  G    47
 072  H    48
 073  I    49
 074  J    4A
 075  K    4B
 076  L    4C
 077  M    4D
 078  N    4E
 079  O    4F
 080  P    50
 081  Q    51
 082  R    52
 083  S    53
 084  T    54
 085  U    55
 086  V    56
 087  W    57
 088  X    58
 089  Y    59
 090  Z    5A
 091  [    5B
 092  \    5C
 093  ]    5D
 094  ^    5E
 095  _    5F
 096  `    60
 097  a    61
 098  b    62
 099  c    63
 100  d    64
 225  á    E1
 226  â    E2
 227  ã    E3
 228  ä    E4
 229  å    E5
 230  æ    E6
 231  ç    E7
 232  è    E8
 233  é    E9
 234  ê    EA
 235  ë    EB
 236  ì    EC
 237  í    ED
 238  î    EE
 239  ï    EF
 240  ð    F0
 241  ñ    F1
 242  ò    F2
 243  ó    F3
 244  ô    F4
 245  õ    F5
 246  ö    F6
 247  ÷    F7
 248  ø    F8
 249  ù    F9
 250  ú    FA

thanks!

You're welcome

Please mark this thread as solved if you have found an answer to your question and good luck!

ok wait im confused this isn't working for me

im getting errors when im trying to put the code in. maybe im doing it wrong??

im getting errors when im trying to put the code in. maybe im doing it wrong??

Maybe. ZIP and upload your project. You can upload files by hitting "Go Advanced" then "Manage Attachments".

here's what i put.
main

using System;

class Class
{
      private void button3_Click(object sender, EventArgs e)
    {
       Class class1 = new Class();
       Class.RunProgram();
    }
}

and then Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace daniweb
{
   public static class Class
   {
      private class IntegerPair
      {
         private int _min;
         private int _max;
         public int Min { get { return _min; } }
         public int Max { get { return _max; } }
         private IntegerPair() { }
         public IntegerPair(int Min, int Max)
            : this()
         {
            this._min = Min;
            this._max = Max;
         }
      }
      private static string GetDisplayString(char c)
      {
         if (char.IsWhiteSpace(c))
            return c.ToString();
         else if (char.IsControl(c))
            return "control";
         else
            return c.ToString();
      }

      public static void RunProgram()
      {
         //from 32 to 100 and then from 225-250
         List<IntegerPair> lst = new List<IntegerPair>();
         lst.Add(new IntegerPair(32, 100));
         lst.Add(new IntegerPair(225, 250));
         foreach (IntegerPair ip in lst)
         {
            for (int i = ip.Min; i <= ip.Max; i++)
            {
               char c = (char)i;
               string display = GetDisplayString(c);
               Console.Write(string.Format("{0: 000}{1, 3}{0, 6:X2}\n", i, display));
            }
         }
      }
   }
}

and then from that it says that Class doesn't contain a definition for RunProgram()

You shouldnt use reserved words for Class/Member names. Why have you changed public static class DisplayPairs to public static class Class ?

Also, the class has been declared as static so you dont need to create an instance of it, static means that there is only ever one instance that exists without being manually instantiated and is refered to by its name. You have correctly called the method: Class.RunProgram(); but by naming the Class as Class you are causing the error.

Also, if the class wasnt static and required instantiating, your code wouldnt work because you are calling the method from the Class not the object of the Class:

Class class1 = new Class();
Class.RunProgram();

//if Class wasnt static, method call should be:
Class class1 = new Class();
class1.RunProgram();

sorry methods confuse me very much so and my teacher replies to me slow since i write a million e-mails

I started writing an explaination and it turned into a tutorial so i put it in a thread here. Hope it helps clear up some of the confusion.

using System;

   public class AsciiTables
   {
      public void FirstAsciiTable()
      {
         Console.Write(" Dec Char  Hex\n -------------\n");
         int min = 032;
         int max = 100;
         for (int i = min; i <= max; i++)
         {
            // get ascii character
            char c = (char)i;

            // get display string
            string display = string.Empty;

            if (char.IsWhiteSpace(c))
            {
               display = c.ToString();
            }
            else if (char.IsControl(c))
            {
               display = "control";
            }
            else
            {
               display = c.ToString();
            }
            // write table row
            Console.Write(string.Format("{0: 000}{1, 3}{0, 6:X2}\n", i, display));

         }
      }// end FirstAsciitable

      public  void SecondAsciiTable()
      {
         Console.Write("  \n Dec Char  Hex\n -------------\n");
         int min = 225;
         int max = 255;
         for (int i = min; i <= max; i++)
         {
            // get ascii character
            char c = (char)i;

            // get display string
            string display = string.Empty;

            if (char.IsWhiteSpace(c))
            {
               display = c.ToString();
            }
            else if (char.IsControl(c))
            {
               display = "control";
            }
            else
            {
               display = c.ToString();
            }
            // write table row
            Console.Write(string.Format("{0: 000}{1, 3}{0, 6:X2}\n", i, display));
         }
      }// end SecondAsciitable

   }// end class

Main method

using System;

public class Ascii
{

   public static void Main(string[] args)
   {
      AsciiTables myAscii = new AsciiTables();

      myAscii.FirstAsciiTable();
      myAscii.SecondAsciiTable();


   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.