public string MoveSpaces(string input) { var arr = input.ToCharArray(); int currentIndex = 0; while (currentIndex < arr.Length - 1 && (currentIndex = Array.IndexOf(arr, ' ', currentIndex + 1)) != -1) { if (_randomiser.Next(100) <= _thresholds.ChanceToMoveSpaces) { if ((char.IsLetterOrDigit(arr[currentIndex - 1]) || char.IsPunctuation(arr[currentIndex - 1])) && currentIndex > 0 && _randomiser.Next(100) <= _thresholds.ChanceToMoveSpacesLeft) { var a = arr[currentIndex]; arr[currentIndex] = arr[currentIndex - 1]; arr[currentIndex - 1] = a; } else if (char.IsLetterOrDigit(arr[currentIndex + 1]) || char.IsPunctuation(arr[currentIndex + 1])) { var a = arr[currentIndex]; arr[currentIndex] = arr[currentIndex + 1]; arr[currentIndex + 1] = a; currentIndex++; } } } return(new string(arr)); }
public string MuddleWord(string input) { if (input.All(char.IsPunctuation)) { return(input); } var noPrecedingPunctuation = Regex.Replace(input, $"^[^a-zA-Z]*", string.Empty); var precedingPunctuation = input.Substring(0, input.Length - noPrecedingPunctuation.Length); var noTrailingPunctuation = Regex.Replace(noPrecedingPunctuation, $"[^a-zA-Z]*$", string.Empty); var trailingPunctuation = noPrecedingPunctuation.Substring(noTrailingPunctuation.Length); var arr = noTrailingPunctuation.ToCharArray(); for (var i = 0; i < arr.Length - 1; i++) { var chance = i == 0 || i == arr.Length - 2 ? _thresholds.ChanceToSwapFirstAndLastCharacters : _thresholds.ChanceToSwapCharacters; if (char.IsLetterOrDigit(arr[i]) && char.IsLetterOrDigit(arr[i + 1]) && _randomiser.Next(100) <= chance) { // swap letters var a = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = a; i++; } } return(precedingPunctuation + new string(arr) + trailingPunctuation); }
public string RemovePunctuation(string input) { var stringBuilder = new StringBuilder(input); for (var i = input.Length - 1; i >= 0; i--) { if (char.IsPunctuation(input, i) && _randomiser.Next(100) <= _thresholds.ChanceToRemovePunctuation) { stringBuilder.Remove(i, 1); } } return(stringBuilder.ToString()); }
public string RemoveCapitalisation(string input) { var num = _randomiser.Next(100); return(num <= _thresholds.ChanceToRemoveCapitals ? input.ToLower() : input); }