add commonly-used extension methods to String

This commit is contained in:
Michael Becker 2020-02-29 17:59:17 -05:00
parent 731a050979
commit c565e8203c
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
2 changed files with 25 additions and 0 deletions

View File

@ -58,6 +58,7 @@
<Compile Include="Logic\ExpressionContext.cs" />
<Compile Include="Logic\Variable.cs" />
<Compile Include="Logic\Expressions\EmptyExpression.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Logic\Expressions\ArithmeticExpression.cs" />
<Compile Include="Logic\VariableRequestedEvent.cs" />
</ItemGroup>

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
namespace MBS.Framework
{
public static class StringExtensions
{
public static string Capitalize(this string value)
{
if (String.IsNullOrEmpty(value)) return value;
if (value.Length == 1) return value.ToUpper();
return value[0].ToString().ToUpper() + value.Substring(1);
}
public static string ReplaceVariables(this string value, Dictionary<string, object> dict)
{
string retval = value;
foreach (KeyValuePair<string, object> kvp in dict)
{
retval = retval.Replace("$(" + kvp.Key + ")", kvp.Value == null ? String.Empty : kvp.Value.ToString());
}
return retval;
}
}
}