/// <summary> /// Used to format a city, state, and zip into a single line. /// </summary> /// <param name="text">Expects city, state, and then zip.</param> /// <returns>City, state, and zip formatted into single line.</returns> public string Format(params string[] text) { var washedText = Perform.NullAndWhitespaceReplace(text); string city = washedText.ElementAtOrDefault(0) ?? ""; string state = washedText.ElementAtOrDefault(1) ?? ""; string zip = ZipCodeFormatter.Format(washedText.ElementAtOrDefault(2) ?? ""); string output = ""; output = TestAndCombine(output, city, ""); output = TestAndCombine(output, state, ", "); output = TestAndCombine(output, zip, " "); return output; }
/// <summary> /// Expects two arguments. Ignores others. Used to format names. /// </summary> /// <param name="text">Text to format.</param> /// <returns>If both arguments are null, empty or whitespace, returns string.Empty. If second argument is missing, just returns first. If both are present, combines with a whitespace.</returns> public string Format(params string[] text) { string[] washedText = Perform.NullAndWhitespaceReplace(text); if (washedText.Any() == false) { return(""); } if (washedText.Length == 1) { return(washedText[0]); } string name = $"{washedText[0]} {washedText[1]}"; return(string.IsNullOrWhiteSpace(name) ? "" : name); }
/// <summary> /// Takes text, links them with InputLink, finds all matches of RegularExpression, links the matches with OutputLink, and outputs result. /// </summary> /// <param name="text">Text to format.</param> /// <returns>If any stage produces an empty string, or there are no matches, EmptyText is returned. Otherwise, the result of operation is.</returns> public string Format(params string[] text) { string input = string.Join(InputLink, Perform.NullAndWhitespaceReplace(text)); if (string.IsNullOrEmpty(input)) { return(EmptyText); } if (string.IsNullOrWhiteSpace(RegularExpression)) { return(EmptyText); } var regularExpression = new Regex(RegularExpression); string outputCandidate = string.Join(OutputLink, regularExpression.Match(input).Groups.Cast <Group>().Skip(1).Select(m => m.Value)); return(string.IsNullOrWhiteSpace(outputCandidate) ? EmptyText : outputCandidate); }
public string Format(params string[] text) { string[] washedText = Perform.NullAndWhitespaceReplace(text); return((NameFormatter?.Format(washedText) ?? "") + (washedText.Length > 2 && washedText[2].IsMeaningful() ? $" {ExtensionPrependage}{washedText[2] }" : "")); }
/// <summary> /// Returns first string that isn't null or, empty, or just whitespace. If no legal string, returns string.Empty. /// </summary> /// <param name="text">Input text.</param> /// <returns>Returns first string that isn't null or, empty, or just whitespace. If no legal string, returns string.Empty.</returns> public string Format(params string[] text) => Perform.NullAndWhitespaceReplace(text).FirstOrDefault(t => string.IsNullOrEmpty(t) == false) ?? "";