-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackSpace.cs
More file actions
31 lines (26 loc) · 844 Bytes
/
BackSpace.cs
File metadata and controls
31 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace CommandDesignPattern;
public class BackSpace : ICommand
{
private int toBeRemovedChars;
private string OriginalString;
public BackSpace(int toBeRemovedChars, string originalString)
{
this.toBeRemovedChars = toBeRemovedChars;
this.OriginalString = originalString;
}
public string TextToExecute(string textToExecute)
{
if (textToExecute.Length >= toBeRemovedChars || toBeRemovedChars != 0)
{
return (textToExecute.Remove((textToExecute.Length) - (toBeRemovedChars), toBeRemovedChars));
}
else
{
return ($"Please enter a number below \n>>:{textToExecute.Length}");
}
}
public string TextToUndo(string textToUndo)
{
return OriginalString.Substring(0, textToUndo.Length + toBeRemovedChars);
}
}