开发者

Processing the string separated by ":" with C#

I need to parse the string separated with ":" to process the contents one by one. I can implement the function with Python as follows:

st = "a:b:c"
h = st.split(":")
for item i开发者_运维问答n h:
    print item

How can I do the same thing with C#?


var st = "a:b:c";
foreach(var item in st.Split(':'))
   Console.WriteLine(item);


string st = "a:b:c";
foreach(string item in st.Split(':'))
    Console.Write(item);


C# has a String.Split function as well, you shouldn't need to change anything in your approach except the syntax.


It's pretty much identical to Python:

var myString = "a:b:c";
var splitString = myString.Split(':');
foreach(var item in splitString)
{
    Console.WriteLine(item);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜