public static bool TryParse(string timeSpan, out TimeSpan result) { try { GroupCollection g; if ((g = Format1.Match(timeSpan)) != null) { result = TimeSpan.FromSeconds(int.Parse(g["Minutes"].Value) * 60 + int.Parse(g["Seconds"].Value)); return(true); } else if ((g = Format2.Match(timeSpan)) != null) { result = TimeSpan.FromSeconds(int.Parse(g["Hours"].Value) * 60 * 60 + int.Parse(g["Minutes"].Value) * 60 + int.Parse(g["Seconds"].Value)); return(true); } else if ((g = Format3.Match(timeSpan)) != null) { result = TimeSpan.FromSeconds(int.Parse(g["Seconds"].Value)); return(true); } else if ((g = Format4.Match(timeSpan)) != null) { result = TimeSpan.FromSeconds(int.Parse(g["Minutes"].Value) * 60); return(true); } } catch { } result = TimeSpan.Zero; return(false); }
public static int ParseReleaseIdFromUri(string uri) { SimpleRegex regex = new SimpleRegex("^http://(www\\.)?discogs\\.com/.*release/(?<releaseId>[1-9][0-9]+?)(\\?.*)?$"); GroupCollection collection = regex.Match(uri); if (collection == null) { return 0; } return int.Parse(collection["releaseId"].Value); }
public static int ParseReleaseIdFromUri(string uri) { SimpleRegex regex = new SimpleRegex("^http://(www\\.)?discogs\\.com/.*release/(?<releaseId>[1-9][0-9]+?)(\\?.*)?$"); GroupCollection collection = regex.Match(uri); if (collection == null) { return(0); } return(int.Parse(collection["releaseId"].Value)); }
public static string ParseArtistNameFromUri(string uri) { SimpleRegex regex = new SimpleRegex("^http://(www\\.)?discogs\\.com/artist/(?<artistName>.+?)(\\?.*)?$"); GroupCollection collection = regex.Match(uri); if (collection == null) { return null; } string artistName = collection["artistName"].Value.Replace('+', ' '); return Uri.UnescapeDataString(artistName); }
public static string ParseArtistNameFromUri(string uri) { SimpleRegex regex = new SimpleRegex("^http://(www\\.)?discogs\\.com/artist/(?<artistName>.+?)(\\?.*)?$"); GroupCollection collection = regex.Match(uri); if (collection == null) { return(null); } string artistName = collection["artistName"].Value.Replace('+', ' '); return(Uri.UnescapeDataString(artistName)); }