Files
Common-VS2019/SacsMobileMaui/Maui/Logic/SamEntryTextFormatter.cs
T

49 lines
1.4 KiB
C#

using Sarand.Net.Standard.Base.Utils;
using System;
namespace Sarand.Net.Mobile.Maui.Logic
{
// --- Entry text formatting ---
public static class SamEntryTextFormatter
{
public static String Format(String? text, SamEntryTextFormatOptions options)
{
String originalText = text ?? "";
String formattedText = originalText;
if (StringUtil.IsEmpty(formattedText)) return formattedText;
if (options.TrimText)
formattedText = StringUtil.TrimAll(formattedText);
if (options.NumericOnly)
{
if (options.Decimals > 0)
{
decimal value = StringUtil.ToDecimal(formattedText);
if (value != 0.0m)
formattedText = value.ToString("N" + options.Decimals);
else if (!formattedText.Equals("0"))
formattedText = "";
}
else
{
long value = StringUtil.ToLong(formattedText);
if (value != 0)
formattedText = value.ToString();
else if (!formattedText.Equals("0"))
formattedText = "";
}
}
else if (options.TextCase == Controls.SamEntry.TextCaseType.Upper)
formattedText = options.TextInfo.ToUpper(formattedText);
else if (options.TextCase == Controls.SamEntry.TextCaseType.Lower)
formattedText = options.TextInfo.ToLower(formattedText);
else if (options.TextCase == Controls.SamEntry.TextCaseType.Title)
formattedText = StringUtil.ToTitleCase(formattedText, options.TextInfo);
return formattedText;
}
// --- The End ---
}
}