All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
asp.net(c#)如何把字符串转换成数组_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:17:31 Browse times: 398 Comment times: 0

asp.net(c#)如何把字符串转换成数组_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

asp.net(c#)如何把字符串转换成数组_[Asp.Net教程] 数据库中记录保存格式是"a,b,c,d",现准备分别取出各值,如果直接取出做数组是不行的,必须进行转换,本文分2种情况,一种是该字符串转换成字符string[]类数组,一种是字符串转换成int[]类数组。

string a = "a,b,c,d";
string b = "1,2,3,4";
string[] arr1 = a.Split(','); //将字符串转换成数组arr1
string[] arrtemp = b.Split(',');
int[] arr2 = new int[arrtemp.Length]; //用来存放将字符串转换成int[]
for(int i = 0; i < arrtemp.Length; i++)
{
arr2[i] = int.Parse(arrtemp[i]);
}




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.