字符串处理
文件操作
集合的使用
String 字符串
增:
Insert()
,string.Join
Replace();
运算符+
string string.Concat(string[]);/string.join("",string[]);
string PadLeft(int,char);//在字符串的左边填充一定空格或字符
删:
string Remove(int startIndex,int count);//"012345".Remove(3,2) =>"0125"
string Substring(int strartIndex,int count)
string Trim()
改:
首先ToCharArray(),再join或Concat或构造函数
查:
bool Contains(string);
int IndexOf(char,int);
int LastIndexOf(char,int);//获得文件名:
bool StartsWinth(string);//以某字符串开头
bool EndsWith(string);//以某字符串结尾
其他
bool string。IsNullorEmpty();
文件是什么?
------>就是一堆字节块
-----> windows 环境下文本文件基本格式
-------------------->字符集的历史:ascii--->双字节--->unicode(utf-16)--->utf-8
-------------------->ANSI
-------------------->Unicode
--------------------> unicode big endim
--------------------->utf-8
如何操作
------------------->用什么类能做什么东西
----------------------->命名空间:System.IO;//input output
----------------------->FileStream 文件流 将文件以字节的方式进行读写
-------------------------------->构造方法:new FileStream(文件路径,FileMode,FileAccess)
FileMode:Create、Append、Open
FileAccess:Write、Read
读写方法:
int ReadByte(); void WriteByte(byte);
int Read(byte[] buffer,int offset,int count);
void Write(byte[] buffer,int offset,int count);
了解
void Flush();//清除缓存,写入硬盘
void Dispose();// 清空非托管资源
Positon属性 //文件处理,指针与文本文件书写是一样的
FileStream 文件操作
FIile
增:
删:
改:
查:
StreamReader
StreamWrite
List<> 集合
List<int> myList=new List<int>();
增:myList.add(1) --无返回值
删:myList.remove(1) ---移除中间的值为1的项 返回是否删除成功的bool值。
改:myList[1]=99 ----将集合中第二个的值更改为99.
查:myList[2] ----查询集合中第三个是多少。
Dictionary[key],[value] 键值对
Dictionary<string,string> myDictionary=new Dictionary<string,string>();
增:myDictionary.Add("Dictionary","字典,字库");
删:myDictionary.Remove("Dictionary");
改:对索引的操作,如:myDictionary["Dictionary"]="字典";
查:对索引的操作
myDictionary.Add("Dictionary", "字典,字库");
myDictionary.Add("love", "爱,爱情");
myDictionary.Remove("love");
myDictionary["Dictionary"]="zi";
Console.WriteLine(myDictionary["Dictionary"]+"\n");
foreach (KeyValuePair<string, string> item in myDictionary)
{
Console.WriteLine(item);
}
Console.ReadKey();