Home > Blockchain >  Get a string inside a string
Get a string inside a string

Time:12-09

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

CodePudding user response:

i think i got it

    char[] delimiterChars = {'-'};

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

CodePudding user response:

This solution using Linq works as well.

var text="100-0-6-7-6-10-8-";
var words=text.Split("-").Where(x => !string.IsNullOrEmpty(x)).ToArray();
  • Related