拆分字符串并将两侧都放入数组中 [英] Split string and place both sides into an array

查看:54
本文介绍了拆分字符串并将两侧都放入数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件需要解析.每行看起来都与此类似:

3BDA22924EF124FB189F1C9E20DE0BE6-1 = TDServerPerks.u

每次都使用相同的格式.我试图将线分成两部分,并将两边放入以等号(=)分隔的两个单独的字符串数组中.如何才能做到这一点?我已经将整个文件读入一个数组,我只需要知道如何将其分开.
谢谢.

I have a text file I need to parse. Each line looks similar to this:

3BDA22924EF124FB189F1C9E20DE0BE6-1=TDServerPerks.u

Same format every time. I am trying to separate the line into two and put both sides into two separate string arrays separated at the equals sign(=). How can this be done? I have read the whole file into an array I just need to know how to separate it.
Thanks.

推荐答案

尝试:
string line = "3BDA22924EF124FB189F1C9E20DE0BE6-1=TDServerPerks.u";
string[] parts = line.Split('=');


string line = "3BDA22924EF124FB189F1C9E20DE0BE6-1=TDServerPerks.u";
string[] parts = line.Split('=');
string[] strItems1 = { parts[0] };
string[] strItems2 = { parts[1] };


您好,您可以使用此

Hi, You can use this

string s = "3BDA22924EF124FB189F1C9E20DE0BE6-1=TDServerPerks.u";
string[] ss = s.Split('=');
string[] a1 = { "your string here" };
List<string> b1 = a1.ToList();
b1.Insert(0,ss[0]); // insert in first position
b1.Add(ss[1]);      // insert in last position
a1 = b1.ToArray();</string>


这篇关于拆分字符串并将两侧都放入数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆