Calculator/Services/InputService.cs
2024-03-29 18:14:12 +03:00

23 lines
728 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace calculator.Services
{
internal class InputService : IInputService
{
public string TryInput(string input)
{
//если есть знак "бесконечность" - не даёт писать цифры после него
if (input.Contains('∞'))
{
input = input[..^1];
}
//ситуация: слева ноль, а после него НЕ запятая, тогда ноль можно удалить
if (input[0] == '0' && (input.IndexOf(".", StringComparison.Ordinal) != 1))
{
input = input.Remove(0, 1);
}
return input;
}
}
}