(c#) How would you go about removing whitespace from a string without the use of methods such as .trim or .replace? : I'm also not allowed to use lists.

My initial thought process for this was to take the initial string then to turn that into a char array. Then after copy everything that is not a space to a second char array. Then convert that char array back to a string.

So quickly it would look something like this;

                char[] firstArray;
                char[] secondArray;
                string someString;

                for (int i = 0; i < someString.Length; i++)
                {
                    firstArray = someString.ToCharArray();
                    secondArray = new char[someString.Length];

                    for (int j = 0; j < firstArray.Length; j++)
                    {
                        if (firstArray[j] != ' ') 
                        {
                            secondArray[j] = firstArray[j];
                        }
                    }

                    someString = secondArray.ToString();
                }


But when I initialise the second char array it would contain an extra char with no value if there was a space in it initially, since it was initialised to the same size as the first char array. Would I have to do a similar loop before just to count the amount of non-spaces then initialise secondArray based off that or is there a much simpler way than all of this that I am missing? (Without the use of .trim, .replace(or anything like them) or lists)

Any help would be appreciated.