Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace StringEdit
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string sentenceCorrection;
  14. int incorrectIndex = 0;
  15. char replacementChar;
  16. int sentenceLength = 0;
  17.  
  18. Program FixTypo = new Program();
  19.  
  20. Console.WriteLine("Which sentence do you want correcting?");
  21. sentenceCorrection = Console.ReadLine();
  22. sentenceCorrection = sentenceCorrection.ToLower();
  23.  
  24. sentenceLength = sentenceCorrection.Length - 1;
  25.  
  26. Console.WriteLine("At which index do you want it correcting? (maximum " + sentenceLength + ")");
  27. incorrectIndex = int.Parse(Console.ReadLine());
  28.  
  29. Console.WriteLine("What do you want to change the character to?");
  30. replacementChar = char.Parse(Console.ReadLine());
  31.  
  32. FixTypo.FixTypo(sentenceCorrection, incorrectIndex, replacementChar);
  33.  
  34.  
  35.  
  36. }
  37.  
  38. public string FixTypo(string sentenceCorrection, int incorrectIndex, char replacementChar)
  39. {
  40. string correctedSentence = "";
  41. char indexLetter;
  42. indexLetter = sentenceCorrection[incorrectIndex];
  43.  
  44. correctedSentence = sentenceCorrection.Replace(indexLetter, replacementChar);
  45.  
  46. Console.WriteLine("The corrected sentence is as follows: ");
  47. Console.WriteLine(correctedSentence);
  48.  
  49. return correctedSentence;
  50. }
  51.  
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement