"IBoughtAnOldIBMXT".InsertCamelCaseSpaces() "TheHTTPProtocol".InsertCamelCaseSpaces() If you know your string contains camel case, you can call the InsertCamelCaseSpaces() extension method directly. "abc-def".Wordify(WordifyOption.ReplaceHypens) "abc-def".Wordify(WordifyOption.AutoDetect) Otherwise, you can pass WordifyOption.AutoDetect and Wordify() will attempt to automatically detect the type of transformation needed. If you know what method should be used for your string, you can achieve a small performance gain by passing the appropriate WordifyOption option. The examples below use the Wordify() extension method. SoftCircuits.Wordify has several methods to help convert symbol names like TotalCount, total_count and total-count to text like total count. New TimeSpan(4, 7, 44).Wordify(3, DateTimeOption.UseWords) įour hours, seven minutes and forty-four seconds Pass a larger number to include additional parts. By default, the precision is 1, and only one part of the time span will be described. This method also takes a precision argument. Here are examples using the version of Wordify() for TimeSpan values. Now.AddHours(-2).AddMinutes(-24).Wordify(DateTimeOption.UseWords) Now.AddHours(2).AddMinutes(24).Wordify() (Note that when using the version that automatically gets the current date and time, that it's possible to have a couple of milliseconds pass before it does.) Code The following examples assume a DateTime variable with the name now. Or, you can supply your own date and time that the description should be relative to. This version of Wordify() describes the relationship between the specified date and time with the current date and time. The library also provides support for describing the differences between two DateTime values. The MakeOrdinalDigits() extension method works similarly but outputs digits instead of words. The library also has support for converting numbers to ordinals using the MakeOrdinal() extention method. For example: 123.67.Wordify(FractionOption.Decimal).Capitalize(). Note: Because most of these methods return strings, it's easy to chain extension method calls. Three hundred forty-five dollars and seventy cents Three hundred forty-five and seven tenthsģ45.7.Wordify(FractionOption.UsCurrency) The one that accepts floating point values also accepts a FractionOption argument that specifies how to format the fractional part. The library can be used to convert numbers to words. And all methods that return a string ensure the return value is never null (unless otherwise documented). Note: Wordify methods that accept a string parameter always correctly handle when that parameter is null. It includes methods to convert numbers and dates to text, insert spaces into camel-case strings, pluralize strings, truncate strings, convert Roman numerals, create memory size strings and much more. Wordify is a static class that contains extension methods to create and modify text.
0 Comments
Leave a Reply. |