String.Split - 如何计算插槽 [英] String.Split - How to calculate slot
问题描述
你好,
看起来很新编程,如果你能帮助我会很棒。
我正在阅读整个.csv文件:
Hello,
look im new in programming, would be awesome if u could help me.
Im reading a whole .csv File with this:
private void button3_Click(object sender, EventArgs e)
{
{
var content = string.Empty;
using (StreamReader reader = new StreamReader(@"C:/1.csv", System.Text.Encoding.Default))
{
content = reader.ReadToEnd();
reader.Close();
}
content = content.Replace("\"", string.Empty);
content = content.Replace(" ", "");
content = content.Replace(" ", "");
using (StreamWriter writer = new StreamWriter(@"C:/2.csv"))
{
writer.Write(content);
writer.Close();
}
}
}
1.CSV输入如下:
< br $> b $ b
09000;Catalaog 1; 10148; 234
09001;Catalaog 2; 0; 345 >
2.CSV这样的展望:
09000~Catalaog 1~10148 ~234
09001~Catalaog 2~0~0
我需要重写我的代码最后分隔的列10148~234得到计算。
字符串必须在最后看起来像这样:
09000~Catalaog 1~9914~234
09001~Catalaog 2~0~0
见差异? 10148 - 234 = 9914. 10148被结果取代。
你可以重写我的高级代码并帮助我吗?:<< / xml>
1.CSV Input looks like this:
" 09000";"Catalaog 1";10148;234
" 09001";"Catalaog 2";0;345
2.CSV Outlooks like this:
09000~Catalaog 1~10148~234
09001~Catalaog 2~0~0
I need a rewrite of my Code that the last delimited Columns 10148~234 get calculated.
String must look like this at the end:
09000~Catalaog 1~9914~234
09001~Catalaog 2~0~0
See the diffrence? The 10148 - 234 = 9914. The 10148 gets replaced with the result.
Could u rewrite my upper code and help me ?:<</xml>
推荐答案
你可以用 ReadAllLines [ ^ ]
结果是文本文件中每个ine的字符串列表或字符串数组。然后你使用拆分 [ ^ ]
现在应该是一个prety直接forword任务,将字符串拆分为; sign。
Well you could read the entire txt file with ReadAllLines[^]
The result for this is a list of string or a array of strings per ine in the text file. Then you make use of Split[^]
It should now be a prety straight forword task to split the string on the ";" sign.
这个新手,你可以重写一下吗?
new to this, could u rewrite it for example?
这篇关于String.Split - 如何计算插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!