c# - Extract all numbers in string to array -


i have string this

+3.15% price per day(+63.00% price @ day 20) 

and want able export array becomes this

{3.15 , 63.00, 20} 

can me this? i'm stuck @ right now, i'm not 100% sure how approach :\ reason why want because want multiple numbers inside string number 4, result become

+12.60% price per day(+252.00% price @ day 20) 

here possible cases

-3.15% price per day(-63.00% price @ day 20)  =>  -12.60% price per day(-252.00% price @ day 20)  +0.76 price per day(+15.20 price @ day 20)  =>  +3.04 price per day(+60.80 price @ day 20) 

// export numbers string input = "+3% price per day(+60% price @ day 20)"; int[] array = regex.matches(input, @"\d+").oftype<match>().select(e => int.parse(e.value)).toarray();  // replace numbers double k = 3; string replaced = regex.replace(input, @"\d+", e => (int.parse(e.value) * k).tostring());  // replace percents k = 4; string replacedpercents = regex.replace(input, @"(\d+)%", e => (int.parse(e.groups[1].value) * k).tostring() + "%");  // floating conversion input = "+0.87 price per day(+63.00 price @ day 20)"; string replacedfloating = regex.replace(input, @"\+(\d+\.(\d+)|\d+)", e => "+" + (double.parse(e.groups[1].value, cultureinfo.invariantculture) * k).tostring(e.groups[2].length == 0 ? "0" : "0." + new string('0', e.groups[2].length), cultureinfo.invariantculture));  // floating conversion negatives input = "-0.87 price per day(+63.00 price @ day 20)"; string replacedfloatingnegative = regex.replace(input, @"([+-])(\d+\.(\d+)|\d+)", e => e.groups[1].value + (double.parse(e.groups[2].value, cultureinfo.invariantculture) * k).tostring(e.groups[3].length == 0 ? "0" : "0." + new string('0', e.groups[3].length), cultureinfo.invariantculture)); 

replaced is

+9% price per day(+180% price @ day 60) 

replacedpercents is

+12% price per day(+240% price @ day 20) 

replacedfloating is

+12.60 price per day(+252.00 price @ day 20) 

replacedfloatingnegative is

-3.48 price per day(+252.00 price @ day 20) 

Comments