Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace String_Stuff
  11. {
  12. public partial class stringForm : Form
  13. {
  14. public stringForm()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private string SwitchCase(string input)
  20. {
  21. string str1 = input;
  22. string output = str1.ToUpper();
  23.  
  24. return output;
  25.  
  26. }
  27.  
  28.  
  29. private string Reverse(string input)
  30. {
  31. string str1 = input;
  32. char[] inputArray = input.ToCharArray();
  33. Array.Reverse(inputArray);
  34. string output = new string(inputArray);
  35.  
  36. return output;
  37. }
  38.  
  39. private string PigLatin(string input)
  40. {
  41. // rules: words that begin with a consinant-
  42. //is moved to the end and "ay" is added.
  43. // words that begin with a vowel-
  44. // the sylable "ay" is added to the end of the word.
  45. // e.g. eagle -> eagleay, apple->appleay.
  46. string str1 = input;
  47. string ay = "ay";
  48. input = inputTextBox.Text; // already a string, no need to convert
  49. input = input.Substring(1, input.Length - 1) + input.Substring(0, 1);
  50. str1 = " the word in Pig Latin is " + input + ay; // need to use Text property to display string
  51. string output= str1 ;
  52. return output;
  53. }
  54.  
  55.  
  56.  
  57. private string ShiftCypher(string input, int shift)
  58. {
  59. //Each letter in the word is replaced by a letter some fixed number of positions down the alphabet.
  60. //For this lab, shift by 3. Example: program, shifted by 3 will become surjudp
  61.  
  62. string output = null;
  63. char[] A = null;
  64. A = input.ToCharArray();
  65. int temp;
  66. for (int i = 0; i < input.Length; i++)
  67. {
  68. temp = (int) (A[i] + shift);
  69. output += (char)temp;
  70. }
  71.  
  72.  
  73. return output;
  74. }
  75.  
  76. private string SubCypher(string input, string charsToSub)
  77.  
  78. {
  79. //Each letter in the word will be replaced by a letter from the corresponding position
  80. //in a substitution alphabet. For this lab use this substitution alphabet: zeroabcdfghijklmnpqstuvwxy.
  81. //Example: disk would become ofqh.
  82. string subAlpha = "zeroabcdfghijklmnpqstuvwxy";
  83. string str1 = input;
  84. string subCypher = subAlpha;
  85.  
  86.  
  87.  
  88. string output = "";
  89. return output;
  90. }
  91.  
  92.  
  93.  
  94. private void transformButton_Click_1(object sender, EventArgs e)
  95. {
  96. string input = inputTextBox.Text;
  97.  
  98. switchCaseTextBox.Text = SwitchCase(input);
  99. reverseTextBox.Text = Reverse(input);
  100. pigLatinTextBox.Text = PigLatin(input);
  101. shiftTextBox.Text = ShiftCypher(input,shift);
  102. subTextBox.Text = SubCypher(input, charsToSub);
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement