c#字符串操作辅助类

简介:

c#字符串操作辅助类

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

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

        
private StringUtil()
ExpandedSubBlockStart.gif        
{
        }


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

        public static string ToCamel(string name)
ExpandedSubBlockStart.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.gif        
/**/
ExpandedSubBlockStart.gif        
/// <summary>
        
/// 移除空格并首字母大写的Pascal样式
        
/// </summary>
        
/// <param name="name"></param>
        
/// <returns></returns>

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



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

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

            
return s;
        }


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

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

            }

            
return s;
        }


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

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


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

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

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

            }

            
return revised;
        }


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

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


            
return false;
        }

    }


    本文转自wenglabs博客园博客,原文链接: http://www.cnblogs.com/xiexiaokui/archive/2008/07/19/1246567.html ,如需转载请自行联系原作者



相关文章
|
1月前
|
C#
C#学习相关系列之数据类型类的三大特性(二)
C#学习相关系列之数据类型类的三大特性(二)
|
1月前
|
C#
58.c#:directory类
58.c#:directory类
12 0
|
1月前
|
C#
57.c#:directorylnfo类
57.c#:directorylnfo类
13 0
|
1月前
|
监控 C#
55.c#:file类
55.c#:file类
16 1
|
1月前
|
算法 C#
54.c#:random类
54.c#:random类
14 1
|
1月前
|
C#
51.c#:string类的静态方法
51.c#:string类的静态方法
20 1
|
1月前
|
C#
27.c#关键字sealed修饰类
27.c#关键字sealed修饰类
12 0
|
1月前
|
C#
深入C#中的String类
深入C#中的String类
11 0
|
1月前
|
C#
C#学习系列相关之多线程(二)----Thread类介绍
C#学习系列相关之多线程(二)----Thread类介绍
|
1月前
|
C#
C#学习相关系列之数据类型类----嵌套类和嵌套方法(三)
C#学习相关系列之数据类型类----嵌套类和嵌套方法(三)