C# 将字符串拆分为单独的变量

标签 c# string split

我试图在发现逗号时将字符串拆分为单独的字符串变量。

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
}

我需要能够为逗号两边的字符串创建一个字符串变量。谢谢。

最佳答案

在这种情况下去掉 ForEach。

只是:

string x = dates[0];
string y = dates[1];

关于C# 将字符串拆分为单独的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7378028/

相关文章:

c# - 如何从方法的 switch 语句返回不确定类型的值

python:可变字符串格式

c - 字符串比较逻辑错误

java - 为什么 java 中的 String.Split(regex) 返回的元素数组的大小小于实际存在的元素大小?

c# - 如何把HH :mm:ss formatted times in CSV so Excel formats them as regular text?

c# - .NET HttpClient 在 Azure WebApp 中响应缓慢或无响应

c# - 从 DataContractJsonSerializer 格式化日期到 iOS

c# - 在 C# 中操作 RichText 的更好方法?

sql-server - SQL CLR 拆分 UDF 中的标识列

java - GWT runAsync - 生成片段代码依赖项