所以在我的游戏中,我试图从数据库中获取一些文章,并将数据拆分为单独的文章。这是我的代码:
IEnumerator Start () {
WWW articleData = new WWW ("http://mywebsite.com/getsomedatabase.php");
yield return articleData;
string articleDataString = articleData.text;
DevideData (articleDataString);
}
void DevideData(string data)
{
//Column 1 = article name
//Column 2 = article id
//Column 3 = option 1
//Column 4 = option 2
//Column 5 = option 3
//Column 6 = change in values that appear directly after article has come in
//Column 7 = change in values after option 1 has been chosen
//Column 8 = change in values after option 2 has been chosen
//Column 9 = change in values after option 3 has been chosen
//Column 10 = change in values after no option has been chosen
List<string> articles = new List<string> ();
string subData = data;
for (int i = 1; i < Regex.Matches (data, "|NEXT|").Count; i++) {
articles.Add(subData.Substring(0,subData.IndexOf ("|NEXT|")));
subData.Replace (subData.Substring (0, subData.IndexOf ("|NEXT|")), "");
}
}
articleDataString基本上是一长串格式化数据,每篇文章用| NEXT |分隔。但是,我用来分割字符串的方法(我甚至不知道它是否正常工作。)对于机器来说太重了。这就是为什么我要问是否有一种更有效,轻量级的分离长弦的方法。
答案 0 :(得分:2)
在C#中,您可以使用String数组重载。像这样:
articleDataString.Split(new string[] { "|NEXT|" }, StringSplitOptions.None);