using System; using System.Collections.Generic; using System.Text; using Activizr.Basic.Interfaces; namespace Activizr.Logic.Support { internal class LogicServices { /// /// Determines if a string can be parsed as an Int32. /// /// String to test. /// True if safely parsable by Int32.Parse. internal static bool IsNumber (string input) { try { Int32.Parse (input); return true; } catch (Exception) { return false; } } /// /// Removes any non-digits from a string. /// /// The string to clean. /// The sanitized result. /// This means that an input string of "abc153ûû" would come back as "153". internal static string CleanNumber (string input) { if (input == null) { return string.Empty; } var result = new StringBuilder(); foreach (char acter in input) { if (acter >= '0' && acter <= '9') { result.Append (acter); } } return result.ToString(); } internal static int[] ObjectsToIdentifiers (IHasIdentity[] identifiables) { var result = new List(); result.Capacity = identifiables.Length*11/10; foreach (IHasIdentity identifiable in identifiables) { result.Add (identifiable.Identity); } return result.ToArray(); } } }