Search code examples
c#stringnumberssequence

Get a string inside a string


string a = "100-0-6-7-6-10-8-" //and so on

/////////////////////////////////////////////
//my solution

char[] delimiterChars = {'-'};

    string solution = "100-0-6-7-6-10-8-";
    string[] words = solution.Split(delimiterChars,System.StringSplitOptions.RemoveEmptyEntries);

//ok so i encounter some problems when trying to overwrite 0s, and 10s,100s etc
//so when writing data to the "solution" string it should be 
//"-100--0--6--7--6--10--8-" instead of "100-0-6-7-6-10-8-"


basically, I want to separate each number and put it in a list or array


Solution

  • i think i got it

        char[] delimiterChars = {'-'};
    
        string text = "100-0-6-7-6-10-8-";
        string[] words = text.Split(delimiterChars,System.StringSplitOptions.RemoveEmptyEntries);