0

So in my game I'm trying to get some articles from a database and split the data in separate articles. Here's my code:

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 is basically a long string of formatted data, and each article is separated by |NEXT|. However, the method I'm using to split the string, (I don't even know if it works yet.) is too heavy for the machine to handle. That's why I'm asking if there's a more efficient, lightweighted way of separating the long string.

ChiragMM
  • 347
  • 4
  • 12
Amalox
  • 3
  • 1
  • 5

1 Answers1

2

In C#, you can use the String array overload. Like this:

articleDataString.Split(new string[] { "|NEXT|" }, StringSplitOptions.None);
Andrea
  • 6,032
  • 2
  • 28
  • 55
  • 1
    Thanks so much! That's way easier than what I was trying to do haha. – Amalox Apr 02 '18 at 12:56
  • Yes, this! I would also add that by replacing the delimiter `|NEXT|` with something more compact, such as a vertical bar | (or similar), will reduce bandwidth and save a little overhead during the Split. – Lece Apr 02 '18 at 12:56
  • Hmm... Good point. I'll change that as well then. Thanks again! – Amalox Apr 02 '18 at 13:00
  • 1
    @Amalox if this answers your question, don't forget to accept it. :) – Lece Apr 02 '18 at 13:09