-3

I'm trying to get the three types of variavles, and comma. using this RegEx

"(\"(?:\"\"|[^\"])*\"|(?:true|false)*(?:\\d+)*(?:[,])*)"

The text pattern is something like this:

"Felis Catus", true, false, 18

"Pig "eggos" domesticus", , false, 6

"Gallus domesticus", false, true, 5

The string and number is doing well, but i can't get the comma separated from bool values, i get mathces like this:

"Felis Catus"

,

true,

false,

18

Comma must be separated from, in my example (true and false) The output must be:

"Felis Catus"

,

true

,

false

,

18

4

1 回答 1

1

忘记正则表达式,只需执行String.Split...

string s = "\"Felis Catus\", true, false, 18";
string[] parts = s.Split(',');

string text = parts[0];//"Felis Catus"
bool b1 = parts[1].Trim() == "true";//true
bool b2 = parts[2].Trim() == "true";//false
int number = int.Parse(parts[3]);//18
于 2013-09-03T10:57:30.083 回答