当前位置:编程学习 > C#/ASP.NET >>

help!!! reformat string using c#

Input: ^Cantos^Kenneth^A^^MD^^^
Definition: ^ is used to identify each element, for example in this case, Cantos Kenneth A and MD are four elements. 
Requirement: remove the first element and make sure the final output shown below.

输出的最终结果为: ^Lname^Fname^MidName

Note: 输入的字符串长度不定

Thanks in advance for any input, --------------------编程问答-------------------- --------------------编程问答-------------------- 嘿嘿,本来想来帮LZ分析分析什么问题,可一看是E文,俺看不懂了,帮顶了。。 --------------------编程问答-------------------- 没看懂需求,移除掉第一个项,输出如下   怎么扯到 name了? what's  name? --------------------编程问答--------------------
引用 3 楼 zhenglj 的回复:
没看懂需求,移除掉第一个项,输出如下 怎么扯到 name了? what's name?


输出的最终结果为: ^Kenneth^A^MD
--------------------编程问答-------------------- string input = "^Cantos^Kenneth^A^^MD^^^";
string[] inputtemp = input.Split['^'];
System.Collections.Specialized.StringCollection newinput = new System.Collections.Specialized.StringCollection();
string inputiteration = string.Empty;
string output = string.Empty;
for (int i=0; i<inputtemp.length; i++)
if (inputtemp[i] !="")
{
  newinput.Add("^"+inputtemp[i]);
}
/*in my case, I need to finalize the format of output like **^Lastname^Firstname^Middlename
*/

if (newinput.Count > 3)
                        {
                                output = newinput[0] + newinput[1] + newinput[2];
                        }
                        else
                        {
                                foreach ( string str in newinput)
                                    inputiteration += str;
                                output = inputiteration + "^" + "No MiddleName";
                        }


I think I got it.
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,