c# - Using Regular Expression for assigning multiple variables -


I have an XML duration in the format of "0H0M0.25S", where H, M, S stands for hours , Months, second. Now I want to parse this string and assign it to hours, minutes, and dual seconds of the integer. I.e.

  string s = "0H0M0.25S"; // Input int, minutes; Double seconds; // to assign   

Is there a way to get it using regular expression, which can specify all the variables at once?

Try this:

  var results = reges. Match (S, @ "(\ d *) H (\ d *) M (\ d *. \ D *)"); Hour = int.Parse (result group [1]. Value); Minute = int.Parse (result group [2]. Value); Second = Double. Purse (result group [3]. Value);   

You may need to compensate for culture during the parsing of double.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -