dictionary - Catch strings between double quotes in a text and map their indexes into array, C# -


i have string:

string text1 = "lorem \"ipsum dolor\" quisque @ \"massa non erat\". donec auctor \"blandit\" nibh!"; 

i looking solution that:

1) catches words between double quotes and,

2) assigns them value of 10 so:

int[] result = {0,10,10,0,0,10,10,10,0,0,10,0}  

thank you.

try this:

var text1 = "lorem \"ipsum dolor\" quisque @ \"massa non erat\". donec auctor \"blandit\" nibh!";  var output =     text1         .split('"')         .selectmany((x, n) => x.trim().split(' ').select(y => n % 2 == 0 ? 0 : 10))         .toarray(); 

it produces int[] result = new [] { 0, 10, 10, 0, 0, 10, 10, 10, 0, 0, 0, 10, 0 }.

that's not you're after, fact there's . after second set of double quotes makes code think . valid word. might need think how clean string first.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -