using System.Text.RegularExpressions;
string line;
string resultString;
float a;
Regex regex = new Regex(@"[-+]?[0-9]*\.?[0-9]*");
resultString = regex.Match(line).Groups[1].Value;
a=float.Parse(resultString);
it returns “invalid format”
When I remove the parse instruction and when I display resultString the string is empty. I checked that the input string (named line) is correct : it is “Pcy1_7R12=-0.001111971”
I don’t remember how to properly use this kind of syntax [-+]?[0-9].?[0-9] But… you have an error there i think it should be like this [-+]?[0-9]+(.[0-9]+)? Edit:
sorry quickly rechecked the wiki, fixed my own error
By memory leaks I expect you mean garbage generation (memory for the GC to clean up) - I’d assume that using a regex is going to be more costly in terms of memory use and CPU consumption (it’s got a lot more work to do). This is 100% assumption and should not be taken as fact.
BUT, if you’re not doing this in Update() or similar - for example, if you’re only doing this at scene or game start or due to single events happening infrequently, then caring about either is wasted effort. Just use what’s easiest and consult the profiler to find any real world issues.