<p>I have some strings of xxh:yym format where xx is hours and yy is minutes like "05h:30m". What is an elegant way to convert a string of this type to TimeSpan?</p>

[{'answer_id': 26769, 'author': 'Lars Mæhlum', 'author_id': 960, 'author_profile': 'https://Stackoverflow.com/users/960', 'pm_score': 6, 'selected': True, 'text': '<p>This seems to work, though it is a bit hackish:</p>\n\n<pre><code>TimeSpan span;\n\n\nif (TimeSpan.TryParse("05h:30m".Replace("m","").Replace("h",""), out span))\n            MessageBox.Show(span.ToString());\n</code></pre>\n'}, {'answer_id': 26775, 'author': 'bdukes', 'author_id': 2688, 'author_profile': 'https://Stackoverflow.com/users/2688', 'pm_score': 1, 'selected': False, 'text': '<p>Are <a href="http://msdn.microsoft.com/en-us/library/system.timespan.parse.aspx" rel="nofollow noreferrer">TimeSpan.Parse</a> and <a href="http://msdn.microsoft.com/en-us/library/system.timespan.tryparse.aspx" rel="nofollow noreferrer">TimeSpan.TryParse</a> not options?  If you aren\'t using an "approved" format, you\'ll need to do the parsing manually.  I\'d probably capture your two integer values in a regular expression, and then try to parse them into integers, from there you can create a new TimeSpan with its constructor.</p>\n'}, {'answer_id': 26778, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 3, 'selected': False, 'text': "<p><code>DateTime.ParseExact</code> or <code>DateTime.TryParseExact</code> lets you specify the exact format of the input. After you get the <code>DateTime</code>, you can grab the <code>DateTime.TimeOfDay</code> which is a <code>TimeSpan</code>.</p>\n\n<p>In the absence of <code>TimeSpan.TryParseExact</code>, I think an 'elegant' solution is out of the mix.</p>\n\n<p>@buyutec As you suspected, this method would not work if the time spans have more than 24 hours.</p>\n"}, {'answer_id': 26780, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'e one possibility:</p>\n\n<pre><code>TimeSpan.Parse(s.Remove(2, 1).Remove(5, 1));\n</code></pre>\n\n<p>And if you want to make it more elegant in your code, use an extension method:</p>\n\n<pre><code>public static TimeSpan ToTimeSpan(this string s)\n{\n  TimeSpan t = TimeSpan.Parse(s.Remove(2, 1).Remove(5, 1));\n  return t;\n}\n</code></pre>\n\n<p>Then you can do </p>\n\n<pre><code>"05h:30m".ToTimeSpan();\n</code></pre>\n'}, {'answer_id': 952947, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>From another thread:</p>\n\n<p><a href="https://stackoverflow.com/questions/62804/how-to-convert-xs-duration-to-timespan-in-vb-net/63219#63219">How to convert xs:duration to timespan</a></p>\n'}]
['https://Stackoverflow.com/questions/26760', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/31505/']