public string Sith(TextForSith input) { string[] sentences = input.Text.Split('.', StringSplitOptions.RemoveEmptyEntries); List <string> yodaTalk = new List <string>(); List <string> yodaSentences = new List <string>(); foreach (var sentence in sentences) { string[] words = sentence.Split(" ", StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < words.Length; i++) { if (i == 1) { yodaTalk.Add(Capitalize(words[i])); yodaTalk.Add(words[i - 1].ToLower()); } else if (i % 2 == 1) { yodaTalk.Add(words[i].ToLower()); yodaTalk.Add(words[i - 1].ToLower()); } } if (words.Length % 2 == 1) { yodaTalk.Add(words[words.Length - 1].ToLower()); } string yodaSentence = string.Join(" ", yodaTalk) + "."; yodaTalk.Clear(); yodaSentences.Add(yodaSentence); } string yodaString = string.Join(" ", yodaSentences); return(yodaString); }
public JsonResult Sith(TextForSith input) { logServices.SaveToDatabase(new Log(HttpContext.Request.RouteValues["action"].ToString(), JsonSerializer.Serialize(input))); if (input?.Text == null) { return(Json(new { error = "Feed me some text you have to, padawan young you are. Hmmm." })); } return(Json(new { sith_text = restServices.Sith(input) })); }