易字符串解析 [英] Easy string parsing
本文介绍了易字符串解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我需要用逗号连接它们的一些字符串化的价值观,我做的,例如:
When I need to stringify some values by joining them with commas, I do, for example:
string.Format("{0},{1},{3}", item.Id, item.Name, item.Count);
和有,例如,12,苹果20
。结果
然后,我想做相反的操作,得到给定的字符串值。是这样的:
And have, for example, "12,Apple,20"
.
Then I want to do opposite operation, get values from given string. Something like:
parseFromString(str, out item.Id, out item.Name, out item.Count);
我知道,这是可能的C.但是我不知道在C#这样的功能。
I know, it is possible in C. But I don't know such function in C#.
推荐答案
是的,这是很容易做到。你只需要使用 String.Split
法分裂每个逗号字符串
Yes, this is easy enough. You just use the String.Split
method to split the string on every comma.
例如:
string myString = "12,Apple,20";
string[] subStrings = myString.Split(',');
foreach (string str in subStrings)
{
Console.WriteLine(str);
}
这篇关于易字符串解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文