forked from TheAlgorithms/C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator.cs
35 lines (32 loc) · 945 Bytes
/
Translator.cs
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
using System.Collections.Generic;
using System.Text;
namespace Algorithms.DataCompression
{
/// <summary>
/// TODO.
/// </summary>
public class Translator
{
/// <summary>
/// TODO.
/// </summary>
/// <param name="text">TODO. 2.</param>
/// <param name="translationKeys">TODO. 3.</param>
/// <returns>TODO. 4.</returns>
public string Translate(string text, Dictionary<string, string> translationKeys)
{
var sb = new StringBuilder();
var start = 0;
for (var i = 0; i < text.Length; i++)
{
var key = text.Substring(start, i - start + 1);
if (translationKeys.ContainsKey(key))
{
_ = sb.Append(translationKeys[key]);
start = i + 1;
}
}
return sb.ToString();
}
}
}