C#将字符串拆分为单独的变量 [英] C# Split String Into Separate Variables
本文介绍了C#将字符串拆分为单独的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
发现逗号时,我试图将字符串拆分为单独的字符串变量.
I am trying to split a string into separate string variables when a comma is found.
string[] dates = line.Split(',');
foreach (string comma in dates)
{
string x = // String on the left of the comma
string y = // String on the right of the comma
}
我需要能够为逗号两侧的字符串创建一个字符串变量.谢谢.
I need to be able to create a string variable for the string on each side of the comma. Thanks.
推荐答案
在这种情况下,请摆脱ForEach.
Get rid of the ForEach in this case.
就这样:
string x = dates[0];
string y = dates[1];
这篇关于C#将字符串拆分为单独的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文