-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringService.cs
More file actions
41 lines (29 loc) · 1.24 KB
/
StringService.cs
File metadata and controls
41 lines (29 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
using System;
namespace StringProcessingApp.Services
{
public class StringService
{
private string _originalText = string.Empty;
private string _currentText = string.Empty;
public void SetText(string text)
{
_originalText = text;
_currentText = text;
}
public string GetCurrentText() => _currentText;
public void ToUpper() => _currentText = _currentText.ToUpper();
public void ToLower() => _currentText = _currentText.ToLower();
public int GetLength() => _currentText.Length;
public bool ContainsWord(string word) => _currentText.Contains(word, StringComparison.OrdinalIgnoreCase);
public void ReplaceWord(string oldWord, string newWord) =>
_currentText = _currentText.Replace(oldWord, newWord);
public string ExtractSubstring(int startIndex, int length)
{
if (startIndex < 0 || startIndex + length > _currentText.Length)
return "Error: Out of range.";
return _currentText.Substring(startIndex, length);
}
public void TrimSpaces() => _currentText = _currentText.Trim();
public void Reset() => _currentText = _originalText;
}
}