| | 1 | | @using System.Text |
| | 2 | | @using Utility.Common; |
| | 3 | | @using System.Globalization |
| | 4 | |
|
| | 5 | | @inject IJSRuntime JSRuntime |
| | 6 | |
|
| | 7 | | <div class="container"> |
| | 8 | | <div class="row"> |
| | 9 | | <div class="col"> |
| | 10 | | <h2>String Converter</h2> |
| | 11 | | </div> |
| | 12 | | </div> |
| | 13 | |
|
| | 14 | | <div class="row"> |
| | 15 | | <div class="col"> |
| | 16 | | <h4>Selected - @choice.Name</h4> |
| | 17 | | <EditForm Model="choice"> |
| | 18 | | <InputRadioGroup @bind-Value="choice.Name"> |
| 0 | 19 | | @foreach (var option in Options) |
| 0 | 20 | | { |
| | 21 | | <InputRadio Value="option" /> @option <br /> |
| 0 | 22 | | } |
| | 23 | | </InputRadioGroup> |
| | 24 | | </EditForm> |
| | 25 | | </div> |
| | 26 | | </div> |
| | 27 | |
|
| | 28 | | <div class="row"> |
| | 29 | | <div class="col"> |
| | 30 | | <div class="input-group"> |
| | 31 | | <textarea id="stringconverter" class="form-control" rows="5">@Input</textarea> |
| | 32 | | <span class="input-group-btn"> |
| | 33 | | <button id="btnStringConverter" name="btnStringConverter" class="btn btn-success float-right" @oncli |
| | 34 | | <button id="btnClearStringConverter" name="btnClearStringConverter" class="btn btn-danger float-righ |
| | 35 | | </span> |
| | 36 | | </div> |
| | 37 | |
|
| | 38 | | </div> |
| | 39 | | </div> |
| | 40 | |
|
| | 41 | | <div class="row"> |
| | 42 | | <div class="col"> |
| | 43 | | <div class="input-group"> |
| | 44 | | <textarea id="outputStringConverter" class="form-control" rows="5" @bind="Output"></textarea> |
| | 45 | | <span class="input-group-btn"> |
| | 46 | | <button id="btnCopyStringConverter" name="btnCopyStringConverter" class="btn btn-info float-right" @ |
| | 47 | | </span> |
| | 48 | | </div> |
| | 49 | | </div> |
| | 50 | | </div> |
| | 51 | |
|
| | 52 | | </div> |
| | 53 | |
|
| | 54 | | @code { |
| 0 | 55 | | string Input = "the quick brown fox jumps over the lazy dog"; //string.Empty; |
| 0 | 56 | | string Output = string.Empty; |
| | 57 | |
|
| 0 | 58 | | Choice choice = new Choice() |
| 0 | 59 | | { |
| 0 | 60 | | Name = "Sentence case" |
| 0 | 61 | | }; |
| 0 | 62 | | List<string> Options = new List<string> { "Sentence case", "lower case", "UPPER CASE", "Capitalized Case", "aLtErNaT |
| | 63 | |
|
| | 64 | | private void Convert() |
| 0 | 65 | | { |
| 0 | 66 | | TextInfo ti = CultureInfo.CurrentCulture.TextInfo; |
| | 67 | |
|
| 0 | 68 | | switch (choice.Name) |
| | 69 | | { |
| | 70 | | case "Sentence case": |
| 0 | 71 | | Output = Input.FirstCharToUpper(); |
| 0 | 72 | | break; |
| | 73 | | case "lower case": |
| 0 | 74 | | Output = Input.ToLower(); |
| 0 | 75 | | break; |
| | 76 | | case "UPPER CASE": |
| 0 | 77 | | Output = Input.ToUpper(); |
| 0 | 78 | | break; |
| | 79 | | case "Capitalized Case": |
| 0 | 80 | | Output = ti.ToTitleCase(Input); |
| 0 | 81 | | break; |
| | 82 | | case "aLtErNaTiNg cAsE": |
| 0 | 83 | | break; |
| | 84 | | case "Title Case": |
| 0 | 85 | | Output = ti.ToTitleCase(Input); |
| 0 | 86 | | break; |
| | 87 | | case "InVeRsE CaSe": |
| 0 | 88 | | Output = Input.Invert(); |
| 0 | 89 | | break; |
| | 90 | | case "Remove Whitespace": |
| 0 | 91 | | Output = String.Concat(Input.Where(c => !Char.IsWhiteSpace(c))); |
| 0 | 92 | | break; |
| | 93 | | } |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | private void Clear() |
| 0 | 97 | | { |
| 0 | 98 | | Input = string.Empty; |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | async Task Copy() |
| 0 | 102 | | { |
| 0 | 103 | | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | public class Choice |
| | 107 | | { |
| 0 | 108 | | public string Name { get; set; } |
| | 109 | | } |
| | 110 | |
|
| | 111 | | } |