title: how to fix error with Substring and IndexOf c#
body: <p>i dont know how to fix this runtime error:</p>
  
  <p><a href="http://postimg.org/image/hh9vl7hi9/" rel="nofollow">http://postimg.org/image/hh9vl7hi9/</a></p>
  
  <p>The value of roomsInfo is : "@114|mag|nir|1||dan|nir|1||\0"
  and it crash when the value is : "dan|nir|1||\0"
  (in the second time of the while) when i try to do this line: </p>
  
  <pre><code>roomsInfo = roomsInfo.Substring(roomsInfo.IndexOf('|') + 1, roomsInfo.IndexOf('\0'));
  </code></pre>
  
  <p>this is the full code:</p>
  
  <pre><code>    String roomsInfo = Program.sendToServ("@10||");
          String[] room_name = new String[100];
          String[] admin_name = new String[100];
          String[] number_of_people = new String[100];
          int check = 0, count = 0;
          if(roomsInfo.IndexOf('\0') &gt; 5)
          {
              roomsInfo = roomsInfo.Substring(roomsInfo.IndexOf('|')+1, roomsInfo.IndexOf('\0'));
              while (roomsInfo[roomsInfo.IndexOf('|') + 2] != '\0' &amp;&amp; roomsInfo[roomsInfo.IndexOf('|') + 1] != '\0') // @114|roomName1|RoomAdmin1|count1||roomName2|RoomAdmin2|count2||
              {
                  if (check == 0)
                  {
                      room_name[count] = roomsInfo.Substring(0, roomsInfo.IndexOf('|'));
                      check = 1;
                      roomsInfo = roomsInfo.Substring(roomsInfo.IndexOf('|') + 1, roomsInfo.IndexOf('\0'));
                  }
                  if (check == 1)
                  {
                      admin_name[count] = roomsInfo.Substring(0, roomsInfo.IndexOf('|'));
                      check = 2;
                      roomsInfo = roomsInfo.Substring(roomsInfo.IndexOf('|') + 1, roomsInfo.IndexOf('\0'));
                  }
                  if (check == 2)
                  {
                      number_of_people[count] = roomsInfo.Substring(0, roomsInfo.IndexOf('|'));
                      check = 0;
                      count++;
                      roomsInfo = roomsInfo.Substring(roomsInfo.IndexOf('|') + 2, roomsInfo.IndexOf('\0'));
                  }
  
              }
          }
  </code></pre>
  
  <p>Thank you!
  Nir</p>