Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Reflection.Metadata.Ecma335;
- using System.Text;
- using System.Xml;
- namespace TransformerToWords
- {
- /// <summary>
- /// Implements transformer class.
- /// </summary>
- public class Transformer
- {
- /// <summary>
- /// Transforms each element of source array into its 'word format'.
- /// </summary>
- /// <param name="source">Source array.</param>
- /// <returns>Array of 'word format' of elements of source array.</returns>
- /// <exception cref="ArgumentNullException">Thrown when array is null.</exception>
- /// <exception cref="ArgumentException">Thrown when array is empty.</exception>
- /// <example>
- /// new[] { 2.345, -0.0d, 0.0d, 0.1d } => { "Two point three four five", "Minus zero", "Zero", "Zero point one" }.
- /// </example>
- public string[] Transform(double[]? source)
- {
- string buffer = string.Empty;
- string[] result = new string[source.Length];
- for (int i = 0; i < source.Length; i++)
- {
- switch (source[i])
- {
- case double.NaN:
- result[i] = "Not a Number";
- continue;
- case double.NegativeInfinity:
- result[i] = "Negative Infinity";
- continue;
- case double.PositiveInfinity:
- result[i] = "Positive Infinity";
- continue;
- }
- buffer = source[i].ToString();
- for (int j = 0; j < buffer.Length; j++)
- {
- switch (buffer[i])
- {
- case '-':
- result[i] += " minus";
- break;
- case '.':
- result[i] += " point";
- break;
- case 'e':
- result[i] += " E plus";
- break;
- case '0':
- result[i] += " zero";
- break;
- case '1':
- result[i] += " one";
- break;
- case '2':
- result[i] += " two";
- break;
- case '3':
- result[i] += " three";
- break;
- case '4':
- result[i] += " four";
- break;
- case '5':
- result[i] += " five";
- break;
- case '6':
- result[i] += " six";
- break;
- case '7':
- result[i] += " seven";
- break;
- case '8':
- result[i] += " eight";
- break;
- case '9':
- result[i] += " nine";
- break;
- }
- }
- result[i] = result[i].Remove(0, 1);
- result[i] = result[i].ToUpper() + result[i].Substring(1).ToLower();
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement