标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharpCharacteric { /// <summary> /// 扩展方法类 /// </summary> public static class Extension { /// <summary> /// 去除字符串中的空格 /// </summary> /// <param name="data">字符串数据</param> public static string NoSpaces(this string data) { return data.Replace(" ",""); } /// <summary> /// 将字符串转化为数字 /// </summary> /// <param name="data">字符串</param> /// <returns>转换结果,如不能转换则返回0</returns> public static int ToInt(this string data) { int result=0; Int32.TryParse(data,out result); return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharpCharacteric { /// <summary> /// 入口类 /// </summary> public class Program { /// <summary> /// 入口方法 /// </summary> /// <param name="args"></param> public static void Main(string[] args) { string data = "This is my computer."; string afterString=data.NoSpaces(); Console.WriteLine(afterString); Console.WriteLine("1234".ToInt()); Console.WriteLine("12.3".ToInt()); Console.WriteLine("abc".ToInt()); } } }
标签:
原文地址:http://www.cnblogs.com/mtsl/p/4234601.html