替换成字符串?

替换成字符串?

问题描述:


我已经声明了3个字符串数组

Hi
I have declared 3 string arrays

string[] Arr1 = new string[] { "a", "b", "c", "", ""};
string[] Arr2 = new string[] { "", "", "", "1", "2" };
string[] Arr3 = new string[5];



我希望将所需的输出作为
"a","1","b","2","c".

任何帮助或建议都将被接受和赞赏.

问候,
帕万.



i want the desired output into Arr3 as
"a","1","b","2","c".

Any Help or suggestion would be accepted and appreciated.

Regards,
Pawan.

帕万,

这是我一小时的努力.
我尽力解决了您遇到的棘手问题.

这是我的代码,
Hi Pawan,

Here is my effort of 1 hour.
I tried my best to accomplish to your tricky problem.

Here is my code,
int arr1Counter = -1;
            int arr2Counter = -1;
            for (int i = 0; i < Arr3.Length; i = i + 2)
            {
                arr1Counter++;
                arr2Counter++;
                if (arr1Counter < 5)
                {
                    while (Arr1[arr1Counter].ToString() == String.Empty)
                    {
                        arr1Counter++;
                    }
                }
                Arr3[i] = Arr1[arr1Counter];
                if (arr2Counter < 5)
                {
                    while (Arr2[arr2Counter].ToString() == String.Empty)
                    {
                        arr2Counter++;
                    }
                }
                if (i < 4)
                    Arr3[i + 1] = Arr2[arr2Counter];
            }


如果需要,请投票标记为答案.


Please vote and Mark as Answer if Helped.


请参见
See here[^] for all the details of the System::String class and its member functions.


您的问题不清楚(您的示例具有变得含糊不清).

对您的问题的答案可能很简单,如通过索引0引用Arr1和通过索引3引用Arr2都进行了硬编码.

我认为这是不可接受的(同样,您还不够清楚).

另一个解决方案可能是ToList您的数组,然后使用Linq查询非空字符串.然后在填充Arr3的Arr1和Arr2之间切换.
Your question is not clear (your example has become to vague).

The answer to your problem could be as simple as referencing Arr1 by the index 0 and referencing Arr2 by index 3 all hard coded.

I assume this is not acceptable though (again you are not being clear enough).

Another solution could be to ToList your arrays and then use Linq to query the non empty strings. Then toggle between your Arr1 and Arr2 filling Arr3.