title: How to check if string character is a space?
body: <p>I've just started programming in C#. I'm trying to build a simple Vigenere text encryption tool as a personal project.</p>
  
  <p>My problem should be very easy to fix, yet it's really stressing me out to find the error. In my code I'm trying to do a simple check to see whether or not the character in my string is a space; I have set up my if statement properly yet it is skipping the first test and moving to the else if, even when the first test is true. Id really like some help on this one.</p>
  
  <p>My problem area is at the bottom.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  public class fun2013
  {
  public static void Main()
  {
      Console.WriteLine("fun 2013");
      string UserName;
      do
      {
          Console.Write("LOGIN//: ");
          UserName = Console.ReadLine();
      }
      while(UserName != "Max");
      Console.WriteLine(("Hello ") + (UserName) + (", enter your key below."));
  
                  //USER ENTERS TEXT AT THIS POINT
  
      string loweredPass = Console.ReadLine().ToLower();
          Console.WriteLine("Changing CASE...");
          Console.WriteLine(loweredPass);
      string Strippedpass = loweredPass.Replace(" ","");
          Console.WriteLine("STRIPPING SPACES...");
          Console.WriteLine(Strippedpass);
      int passLength = Strippedpass.Length;
          Console.WriteLine("Enter your message below.");
      string userMessage = Console.ReadLine();
      int MessageLength = userMessage.Length;
  
                  //BEGIN PROCESSING STRINGS INTO ARRAYS
  
      string temp = "";
      StringBuilder bcon = new StringBuilder();
      char [] passArray = Strippedpass.ToCharArray();
      char [] messArray = userMessage.ToCharArray();
      string letterf = "";
  
      for(int i=0, j=0; j &lt; (MessageLength); i++, j++)    //i used for key array, j used for message length
          {
          &gt;&gt;&gt; if (messArray[i].ToString() == " ")
              {
                  letterf = " ";
              }
          else if (messArray[i].ToString() != " ")
              {
                  letterf = passArray[i].ToString();
              }
              if (i &gt;= (passLength-1))    //array starts at value 0, length check starts at 1. Subtract 1 to keep them equal
                  {i = -1;}   //-1 is used so it will go back to value of 0 on next loop
          temp = letterf;
          bcon.Append(temp);
          }
  
      Console.WriteLine();
      Console.WriteLine(bcon);
  
  
      Console.WriteLine("Press ENTER to continue...");
          Console.ReadLine(); //KILL APPLICATION
  }
  }
  </code></pre>
  
  <p>Thanks for the help everyone, but after further inspection I noticed I made an error in my for loop. I was resetting the message array reader using the same interval as the key array (int i). I changed it to use the correct integer, "j". I also put the "temp" string updater and string builder into each if statement in the loop. It's now running correctly.</p>
  
  <pre><code>    for (int i=0, j=0; j &lt; (MessageLength); i++, j++)    //i used for key array, j used for message length
      {
  
      if (messArray[j].ToString() != " ")
          {
              letterf = passArray[i].ToString();
              temp = letterf;
              bcon.Append(temp);
          }
  
      else if (messArray[j].ToString() == " ")
          {
              letterf = " ";
              temp = letterf;
              bcon.Append(temp);
          }
  
      if (i &gt;= (passLength-1))    //array starts at value 0, length check starts at 1. Subtract 1 to keep them equal
          {i = -1;}   //-1 is used so it will go back to value of 0 on next loop
      }
  </code></pre>