c# Char && string

String str = [null]; 可以用此方法声明一个空字符串
str +"" + str1;
Int Compare(string a,string b)
Int Compare(string a,string b ,bool ignorCase) 第三方参数是true 忽略大小写
String.Compare("aaa","bbb");
int flag = str1.CompareTo("aab");
string a = "aab";
string b = "aac";
bool c = a.Equals(b);
Console.WriteLine(c);
string newstr = String.Format("aaa{0} bbb {1}","1","2");
Console.WriteLine(newstr);
String a = "abcdefg";
String b = ""; //我测试的 b字符串必须预先定义
b = a.Substring(1,4);
String a = "eeeabcdebcde";
char[] sep = {'a','c'};
String[] b = a.Split(sep);
for (int i = 0; i < sep.Length; i++) {
Console.WriteLine("item {0} {1}",i,b[i]);
}
String a = "abcdefg";
string b;
b = a.Insert(3,"hahaha");
String a = "abcdefg";
string b;
a = a.PadRight(9,'z');
a = a.Remove(3,2); //开始位置 从开始位置删除几个
String a = "abc";
String b;
b = String.Copy(a);
Public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count);
sourceIndex 需要复制的字符串起始位置
destination 目标字符数组
destinationIndex 制定目标数组中的开始存放位置
count 指定要复制的字符个数
例子:
String st1 = "用一生下载你";
char[] str = new char[100];
st1.CopyTo(1,str,0,4); //将字符串st从索引1开始的4个字符串复制到字符数组str中
异常:ArgumentOutOfRangeException
sourceIndex、destinationIndex 或 count 为负
count 大于从 startIndex 到此实例末尾的子字符串的长度
count 大于从 destinationIndex 到 destination 末尾的子数组的长度
public string Replace(char OChar,char NChar); 主要用于替换字符串中的字符
public string Replace(string Ovalue,string NValue); 主要用于替换字符串中的字符串
ochar 待替换的字符
nchar 替换后的新字符
ovalue 待替换的字符串
nvalue 替换后的新字符串
String str1 = "用一生下载你";
string b = str1.Replace('一','二'); 替换字符
string c = str1.Replace("用一生","去你妈的"); 替换字符串
c# Char && string的更多相关文章
- const char* && string && String^ 类型转换
const char* && string && String^ 类型转换 const char* ---> string const char * cw= &q ...
- const char* <----- > string
(1) const char* <----- string const char* const_txt_path=txt_path.c_str(); (2) string ...
- c#中 uint--byte[]--char[]--string相互转换汇总
原文:c#中 uint--byte[]--char[]--string相互转换汇总 在在做一些互操作的时候往往需要一些类型的相互转换,比如用c#访问win32api的时候往往需要向api中传入DWOR ...
- 【C语言】reverse_string(char * string)(递归)
递归reverse_string(char * string)性能. 逆转 原始字符串 更改 相反,打印出的. /* 编写一个函数reverse_string(char * string)(递归实现) ...
- MFC中char*,string和CString之间的转换
MFC中char*,string和CString之间的转换 一. 将CString类转换成char*(LPSTR)类型 方法一,使用强制转换.例如: CString theString( &q ...
- CString转char * ,string
CString头文件#include <afx.h> string头文件#include <string.h> 1.CString转char * CString cstr; c ...
- wchar_t char string wstring 之间的转换
wchar_t char string wstring 之间的转换 转:http://blog.csdn.net/lbd2008/article/details/8333583 在处理中文时有时需要进 ...
- VS2013 MFC C++ CString ,const char , char, string 类型转换
VS2013 测试 以下测试加入头文件: # include <string>#include <cstdlib>using namespace std; //-------- ...
- c++编写递归函数char *itostr (int n,char *string),该函数将整数n转换为十进制表示的字符串。
#include<iostream> #include<stdio.h> using namespace std; ; char *itostr (int n,char *St ...
- System::String *,char*,string 等的类型转换 [转]
在VC 的编程中,经常会用到各种类型的转换,在MFC中textbox等控件得到的返回类型是System::String *,而写入的文件要求是 const char *类型的,下面介绍一些转换的方法: ...
随机推荐
- windows c++程序移植到linux的要点
这段时间得到一份源码,是Windows下的,调试了一把,可以正常运行,可是没有Linux版本,而实际的应用场景是要在Linux服务器上面运行 所以涉及到Windows下c++程序的移植,有同事竭力推荐 ...
- JavaScript call()和apply()
ECMAScript规范给所有函数都定义了call()与apply()两个方法,call()与apply()的第一个参数都是需要调用的函数对象,在函数体内这个参数就是this的值,剩余的参数是需要传递 ...
- 学习笔记 - 用js判断页面是否加载完成实现代码
用document.onreadystatechange的方法来监听状态改变, 然后用document.readyState == "complete"判断是否加载完成 docum ...
- bzoj:1941: [Sdoi2010]Hide and Seek
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 531 Solved: 295[Submi ...
- BZOJ 1509: [NOI2003]逃学的小孩
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1509 直接求出树的直径,枚举每个点更新一遍答案. #include<cstring> ...
- hbmy周赛1--C
C - Exam Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- hbmy周赛1--A
Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...
- bat复制文件夹下所有文件到另一个目录
一个需求,网上了半天都是错了,所以记一下吧,方便你我. copy是文件拷贝,文件夹拷贝需要用到xcopy @echo off::当前盘符set curPath=%cd%set digPath =&qu ...
- union 时只能查出一个表中的信息,另一个表只能查出字段
原因:news表中title字段的编码,与brand表中的编码不一致导致 y
- Screen命令安装使用教程
在安装lnmp之前,我们一般先运行一下Screen程序,因为screen好像一个容器一样,把lnmp的安装过程保护了起来.以CentOS中安装lnmp为例,程序下载.编译都需要比较长的时间,如果中途遇 ...