D
D
DD-var2020-02-15 02:35:21
C++ / C#
DD-var, 2020-02-15 02:35:21

How to add 2 characters from box text to array index?

static public List<byte> sed = new List<byte>();
      static public byte[] ded = new byte[0];
        static public string  text;
      static public  int k = 0;
        

  static  public   void sending() 
        {
            text = richT.Text;
            for (int i=0; i<text.Length; i++)
            {
               if(text[i].ToString()!=" ") {

                
                 sed[k]+=   sed.Add(byte.Parse(text[i].ToString()));

                }
                else
                {
                    k++;
                    i++;
                }
               
            }


I am writing such code, I don’t understand how to add characters from the box text to the index until there is a space

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2020-02-15
@Sumor

for (int i=0; i<text.Length; i+=2)
{
  if(text[i] == ' ') break;
  if(i != text.Length-1)
  {
      sed.Add(byte.Parse(text.Substring(i, 2)));
  }
  else
  {
      sed.Add(byte.Parse(text.Substring(i, 1)));
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question