You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
14 years ago
|
using System.Text;
|
||
|
using System.Text.RegularExpressions;
|
||
|
|
||
|
namespace Migrator.Framework
|
||
|
{
|
||
|
public class StringUtils
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Convert a classname to something more readable.
|
||
|
/// ex.: CreateATable => Create a table
|
||
|
/// </summary>
|
||
|
/// <param name="className"></param>
|
||
|
/// <returns></returns>
|
||
|
public static string ToHumanName(string className)
|
||
|
{
|
||
|
string name = Regex.Replace(className, "([A-Z])", " $1").Substring(1);
|
||
|
return name.Substring(0, 1).ToUpper() + name.Substring(1).ToLower();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
///
|
||
|
/// </summary>
|
||
|
/// <param name="template"></param>
|
||
|
/// <param name="placeholder"></param>
|
||
|
/// <param name="replacement"></param>
|
||
|
/// <returns></returns>
|
||
|
public static string ReplaceOnce(string template, string placeholder, string replacement)
|
||
|
{
|
||
|
int loc = template.IndexOf(placeholder);
|
||
|
if (loc < 0)
|
||
|
{
|
||
|
return template;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return new StringBuilder(template.Substring(0, loc))
|
||
|
.Append(replacement)
|
||
|
.Append(template.Substring(loc + placeholder.Length))
|
||
|
.ToString();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|