When we should divide a string to array of strings by a specific delimiters, we can use method String.Splt().
Samples:
string line = "name,id=1234,,description,user=Jon";
string[] lineItems = line.Split(new char[] { ',' });
DisplayOutput(line, lineItems);
lineItems = line.Split(new char[] { ',', '=' });
DisplayOutput(line, lineItems);
lineItems = line.Split(new char[] { ',', '=' }, 2);
DisplayOutput(line, lineItems);
lineItems = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
DisplayOutput(line, lineItems);
lineItems = line.Split(new string[] { ",", "id=", "user="}, StringSplitOptions.RemoveEmptyEntries);
DisplayOutput(line, lineItems);
References:
No comments:
Post a Comment