从网格中的单元格中分割内容/值

时间:2017-10-25 16:05:45

标签: c# .net wpf

我想从网格中的单元格中拆分内容/值,该网格可能包含整数或小数值,并且字符串是强制性的。

我从变量中的网格中获取了单元格中的内容/值。

例如:

var value = (GridCustomerSupplied.SelectedCells[2].Column.GetCellContent(item) 
             as TextBlock).Text;

但我想将数值和字符串值拆分为不同的变量并进一步使用它们。

2 个答案:

答案 0 :(得分:0)

你可以使用linq滑动价值。

using System.Linq;

string text = from s in value
             select s
             where !Char.IsDigit(s);

var numeric = from n in value
             select n
             where Char.IsDigit(n);

答案 1 :(得分:0)

您也可以尝试使用TryParse函数。请参阅此文档 https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/how-to-determine-whether-a-string-represents-a-numeric-value]

std::ostream::operator<<(void*)