字符串的处理
2008-12-24 14:12
127 查看
using System;
using System.Collections.Generic;
using System.Text;
namespace Ch11Ex02
{
class Program
{
static void Main(string[] args)
{
string str1 = "this is a string";
string str2 = "this";
Console.WriteLine(string.Compare(str1, str2));//比较大小大于为1,小于为-1,等于为0
Console.WriteLine(string.Equals(str1, str2));//结果为true和fasce
Console.WriteLine(str1.IndexOf("is"));//查找
Console.WriteLine(str1.LastIndexOf("is"));
Console.WriteLine("{0}", str1.Insert(2, "abc"));//插入
Console.WriteLine("{0}",str1.Remove(2, 3));//删除
Console.WriteLine("{0}", str1.Replace("this", "that"));//替换
string []str=str1 .Split (' ');//分离
for (int i=0;i<str .Length ;i++)
{
Console .WriteLine (str [i ]);
}
char []charArray=str1.ToCharArray (); //复制
for (int i=0;i<charArray .Length ;i++)
{
Console .WriteLine (charArray [i ]);
}
Console.WriteLine("{0}", str1 .ToUpper ());//转大写
string str5 = " this is a book ";
string str3 = " this is a book";
string str4 = "this a book ";
Console.WriteLine(str5.Trim());//去空格
Console.WriteLine(str3.TrimStart());
Console.WriteLine(str4.TrimEnd());
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Ch11Ex02
{
class Program
{
static void Main(string[] args)
{
string str1 = "this is a string";
string str2 = "this";
Console.WriteLine(string.Compare(str1, str2));//比较大小大于为1,小于为-1,等于为0
Console.WriteLine(string.Equals(str1, str2));//结果为true和fasce
Console.WriteLine(str1.IndexOf("is"));//查找
Console.WriteLine(str1.LastIndexOf("is"));
Console.WriteLine("{0}", str1.Insert(2, "abc"));//插入
Console.WriteLine("{0}",str1.Remove(2, 3));//删除
Console.WriteLine("{0}", str1.Replace("this", "that"));//替换
string []str=str1 .Split (' ');//分离
for (int i=0;i<str .Length ;i++)
{
Console .WriteLine (str [i ]);
}
char []charArray=str1.ToCharArray (); //复制
for (int i=0;i<charArray .Length ;i++)
{
Console .WriteLine (charArray [i ]);
}
Console.WriteLine("{0}", str1 .ToUpper ());//转大写
string str5 = " this is a book ";
string str3 = " this is a book";
string str4 = "this a book ";
Console.WriteLine(str5.Trim());//去空格
Console.WriteLine(str3.TrimStart());
Console.WriteLine(str4.TrimEnd());
Console.ReadKey();
}
}
}
相关文章推荐
- [ASP.NET] C#字符串处理
- MATLAB字符串处理
- Python 处理带有 \u 的字符串
- 关于SQL字符串处理的一些函数
- Shell处理文本字符串常用命令
- hdu 2206IP的计算(sscanf的使用 & 字符串判断处理)
- A 谍报分析 河南第十届ACM真题 【字符串处理】
- 「粗」bold() //使用粗体显示字符串 20140808 ①文本处理
- *入门模拟—字符串处理—A 1082
- c字符串处理函数
- 函数模板返回两个值的最小值,确保能正确处理字符串
- c#中处理字符串常用的函数及方法详细说明
- 【算法入门经典】 字符串处理部分总结
- Symbian C++手机编程中字符串处理
- CodeForces - 827A String Reconstruction(思维+字符串处理)
- POJ 3080 Blue Jeans(字符串处理函数)
- 【C语言】10-字符和字符串常用处理函数
- 批处理通过字符串截取得到文件名
- 字符串的处理[C#]
- 1002.写出这个数(字符串处理)