add commonly-used extension methods to String
This commit is contained in:
parent
731a050979
commit
c565e8203c
@ -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>
|
||||
|
||||
24
MBS.Framework/StringExtensions.cs
Normal file
24
MBS.Framework/StringExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user