分隔字符串中的值 [英] Separating values in a string
本文介绍了分隔字符串中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个字符串,其中值用竖线分隔.
例如-
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10":
我必须从字符串中检索Value7.如何处理?
再见
解决方案
我认为string
类的Split
方法可以如下使用
字符串 val = " ; 字符串 [] vals = val.Split(新 char [] {' |'},StringSplitOptions.RemoveEmptyEntries); 字符串 val7 = vals [ 6 ]; Console.WriteLine(val7);
如果val是这种格式,则可以使用:
字符串 val = " ; 字符串 [] valarr = val.Split(' |' ); 字符串 SeventhVal = valarr [ 6 ];
>
Hello,
I have a string where the values are pipe separated.
Eg-
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10":
I have to retrieve Value7 from the string.How to go about it?
Bye
解决方案
I think theSplit
method ofstring
class can be used as below
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10"; string[] vals = val.Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries); string val7 = vals[6]; Console.WriteLine (val7);
Hi,
If val is in this format you can use:
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10"; string[] valarr=val.Split('|'); string SeventhVal=valarr[6];
这篇关于分隔字符串中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文