c#字符串操作辅助类

ContractedBlock.gif ExpandedBlockStart.gif Code
ExpandedBlockStart.gifContractedBlock.gif/**//**/
ExpandedBlockStart.gifContractedBlock.gif    
/**//// <summary>
    
/// 字符串操作辅助类
    
/// </summary>

    public class StringUtil
ExpandedBlockStart.gifContractedBlock.gif    
{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
一些基本的符号常量#region 一些基本的符号常量

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 点符号 .
        
/// </summary>

        public const string Dot = ".";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 下划线 _
        
/// </summary>

        public const string UnderScore = "_";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 逗号加空格 , 
        
/// </summary>

        public const string CommaSpace = "";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 逗号 ,
        
/// </summary>

        public const string Comma = ",";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 左括号 (
        
/// </summary>

        public const string OpenParen = "(";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 右括号 )
        
/// </summary>

        public const string ClosedParen = ")";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 单引号 '
        
/// </summary>

        public const string SingleQuote = "\'";

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 斜线 \
        
/// </summary>

        public const string Slash = @"\";

        
#endregion


        
private StringUtil()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 移除空格并首字母小写的Camel样式
        
/// </summary>
        
/// <param name="name"></param>
        
/// <returns></returns>

        public static string ToCamel(string name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
string clone = name.TrimStart('_');
            clone 
= RemoveSpaces(ToProperCase(clone));
            
return String.Format("{0}{1}", Char.ToLower(clone[0]), clone.Substring(1, clone.Length - 1));
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 移除空格并首字母大写的Pascal样式
        
/// </summary>
        
/// <param name="name"></param>
        
/// <returns></returns>

        public static string ToCapit(string name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
string clone = name.TrimStart('_');
            
return RemoveSpaces(ToProperCase(clone));
        }



ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 移除最后的字符
        
/// </summary>
        
/// <param name="s"></param>
        
/// <returns></returns>

        public static string RemoveFinalChar(string s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (s.Length > 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                s 
= s.Substring(0, s.Length - 1);
            }

            
return s;
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 移除最后的逗号
        
/// </summary>
        
/// <param name="s"></param>
        
/// <returns></returns>

        public static string RemoveFinalComma(string s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (s.Trim().Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
int c = s.LastIndexOf(",");
                
if (c > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    s 
= s.Substring(0, s.Length - (s.Length - c));
                }

            }

            
return s;
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 移除字符中的空格
        
/// </summary>
        
/// <param name="s"></param>
        
/// <returns></returns>

        public static string RemoveSpaces(string s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            s 
= s.Trim();
            s 
= s.Replace(" """);
            
return s;
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 字符串首字母大写
        
/// </summary>
        
/// <param name="s"></param>
        
/// <returns></returns>

        public static string ToProperCase(string s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
string revised = "";
            
if (s.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if (s.IndexOf(" "> 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    revised 
= Strings.StrConv(s, VbStrConv.ProperCase, 1033);
                }

                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
string firstLetter = s.Substring(01).ToUpper(new CultureInfo("en-US"));
                    revised 
= firstLetter + s.Substring(1, s.Length - 1);
                }

            }

            
return revised;
        }


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
        
/// 判断字符是否NULL或者为空
        
/// </summary>

        public static bool IsNullOrEmpty(string value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (value == null || value == string.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
return true;
            }


            
return false;
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值