c#中string与int,double等之间的类型转换

double和string之间

string strA; 
double dB; 
//字符串转换为浮点数 
strA = "43.23"; 
dB = System.Convert.ToDouble(strA); 
//浮点数转换为字符串 
dB = 234.345; 
strA = dB.ToString(); 

int和string之间

int a = 15;

string s1 = a.ToString();

string s2 = Convert.ToString(a);

string s = "18";

int a1 = int.Parse(s);

int a2;

int.TryParse(s, out a2);

int a3 = Convert.ToInt32(s);

取string字符串后几位数

string nc = "12345"

string b = nc.Remove(0, nc.Length - 2);

---b=“45”

取string字符串中某一段数据

string bb = nc.Substring(0, 4);

---bb =“1234

猜你喜欢

转载自www.cnblogs.com/BottleKing/p/9182695.html
今日推荐