Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8" ?>
- <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>AHString Extentions</Title>
- <Shortcut>ahstring_Extentions</Shortcut>
- <Description>Code snippet created on: 7/9/2009 1:44:00 PM</Description>
- <Author>Andrew Hodgson</Author>
- <SnippetTypes>
- <SnippetType>Expansion</SnippetType>
- </SnippetTypes>
- </Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>type</ID>
- <ToolTip>Property type</ToolTip>
- <Default>string</Default>
- </Literal>
- <Literal>
- <ID>property</ID>
- <ToolTip>Property name</ToolTip>
- <Default>MyProperty</Default>
- </Literal>
- </Declarations>
- <Code Language="csharp">
- <![CDATA[
- #region String Extensions class
- [System.Diagnostics.DebuggerStepThrough]
- public static class StringExtensions {
- public static string ToString(this string s,params object[] args) {
- return string.Format(s,args);
- }
- public static string FormatWith(this string s,params object[] args) {
- return string.Format(s,args);
- }
- public static bool IsNull(this string s) {
- return (s == null
- || s.Length == 0
- || string.IsNullOrWhiteSpace(s));
- }
- public static string ValueIfNull(this string s, string value) {
- if(IsNull(s))
- return value;
- else
- return s;
- }
- public static string ToStringEmpty(this object obj) {
- return obj == null ? string.Empty : obj.ToString();
- }
- public static string ToStringEmpty(this object obj,string valueIfNull) {
- return obj == null ? valueIfNull : obj.ToString();
- }
- public static string ToTitleString(this string s) {
- if(s == null)
- return null;
- string result = "";
- for(int i = 0;i < s.Length;i++) {
- char c = s[i];
- if(char.IsUpper(c)) {
- if(i != 0) {
- int h = i - 1;
- if(h > -1) {
- char p = s[h];
- if(char.IsUpper(p)) {
- result += c.ToString();
- continue;
- }
- }
- result += " ";
- }
- }
- result += c.ToString();
- }
- return result;
- }
- public static string Repeat(this string s,int num) {
- return Repeat(s,num,string.Empty);
- }
- public static string Repeat(this string s,int num,string delimeter) {
- if(IsNull(s))
- return s;
- StringBuilder sb = new StringBuilder();
- for(int i = 0;i < num;i++) {
- sb.Append(s);
- if(delimeter != null)
- sb.Append(delimeter);
- }
- return sb.ToString();
- }
- }
- #endregion
- $end$]]>
- </Code>
- </Snippet>
- </CodeSnippet>
- </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment