c怎麼將陣列分割為字串,c怎麼將一個陣列分割為字串

2021-03-04 01:14:19 字數 7214 閱讀 3503

1樓:隔壁的**

是字串分割陣列吧!

如果有明顯的特徵就好辦!

string s = ;

string useragent=「www/111111/3333332」;

s = useragent.split(new char );

沒有明顯特徵,有擷取規律可以用擷取字串和for迴圈配合!

string imei="1001100210031004"

int chang=imei.length/4;

for(int i=0;i

2樓:匿名使用者

string menuclassids = string.join(",", cid_arr);

c#中如何分割字串?

3樓:

(1)如果字串格式為

:string str="abc#def#hijkl#mn";

string s = str.split(new char );

結果就是:

s[0]="abc";

s[1]="def";

s[2]="hijkl";

s[3]="mn";

(2)如果是單純的字串擷取就簡單了,比如:

string str="abcdefg";

string strnew=str.substring(3,3);

結果是:strnew="def";

c#中如何分割字串

4樓:匿名使用者

可以用split。

比如你先定義一個字串物件:string str="a,b,c,d,e,f,g";

然後你再定義一個陣列 string words=str.split(','); // 這段**就是把str按照逗號進行分割,也就是把str分割成a和b和c和d和e和f和g儲存在你定義的字串陣列words中,此時words[0]=a;words[1]=b;words[2]=c……引用的時候也比較方便。

當然,你可以按照其他符號來分割也行,比如str.split('@'),當然前提是字串中要含有那個符號,如果不含有,此時words[0]=str,就不存在words[1]了。

如果str="abcdefg"; 這時候該如何分割呢?可以這樣寫:string words=str.

split("");// 也就是說按照空來分割,此時得到words[0]=a;words[1]=b;……

其他的用法可以查閱相關的資料,這裡就介紹這麼多。

5樓:

(1)如果字串格式為:

string str="abc#def#hijkl#mn";

string s = str.split(new char );

結果就是:

s[0]="abc";

s[1]="def";

s[2]="hijkl";

s[3]="mn";

(2)如果是單純的字串擷取就簡單了,比如:

string str="abcdefg";

string strnew=str.substring(3,3);

結果是:strnew="def";

6樓:匿名使用者

string.spilt()

string.substring()

substring()常常配合indexof()一起使用,最為常見

7樓:匿名使用者

給你一個完整的**

string nihao1 = "1,2,3,4,5,5,6,3,4,6,4,6,6,4,6";

string nihaome1 = nihao1.split(',');

arraylist nihao121 = new arraylist();

for (int i = 0; i < nihaome1.length; i++)

dropdownlist1.datasource = nihao121;

dropdownlist1.databind();

8樓:匿名使用者

string a="1,2,3,4,5,6";

string str=a.split(',',a);

在迴圈這個陣列!

9樓:匿名使用者

可以使用 string.split

string s = "there is a cat";

//// split string on spaces.

// ... this will separate all the words.

//string words = s.split(' ');

foreach (string word in words)

10樓:匿名使用者

使用的 int list= "1,2,3,4,5,。。。。。".split(',')函式。

11樓:匿名使用者

//try it

using system;

using system.collections.generic;

using system.text;

namespace test

catch

}public static void splid(string s)

console.writeline(temp);

s=s.remove(s.lastindexofany(condition));

goto tryagain;}}}

12樓:柒色散沙

if (!page.ispostback)

13樓:匿名使用者

string cha = "".split(',');

foreach (string str in cha)

14樓:匿名使用者

string numbers="1,2,3,4,5,6".split(",".tochararray());

dropdownlist ddlnumbers=new dropdownlist();

foreach(string str in numbers)

c#如何把字串陣列分割成一個一個值

15樓:匿名使用者

用split方法可以的,用陣列接受split,用2個陣列,然後一一對應起來就可以了。以逗號分隔。

比如:string colors="黃,綠色,青";

string arrays=colors.split(',');

arrays陣列裡就是所以的顏色

然後可以arrays[0]=黃;

這裡可以用迴圈取出每一種顏色,尺寸也是如此。!希望能幫到你。

16樓:匿名使用者

這種題目一般應用於自定義協議的處理:

資料格式為:標記名1:標記值1|標記名2:標記值2|...|標記名n:標記值n

資料中忽略回車換行

這種情況定義一個結構:

struct **ydata

通過一個for迴圈根據分隔符「:」和「|」分別取出結構的名稱和值,並儲存到一個集合中,建議用泛型的tlist

最後按需求輸出

17樓:朱熾明

用split方法可以解決

c#怎麼分割字串為陣列

18樓:匿名使用者

簡單!宣告string的一個陣列:string str;然後str=需要切割的字串.split(' 空格')這就是按空格切割,你也可以自己自定義。明白?

19樓:匿名使用者

string s="1,2,3,4,5";string p=s.split(',');

20樓:匿名使用者

string有一個成員函式split,這可以分隔

21樓:匿名使用者

.split('');

c#怎麼把一串數字分割為陣列

22樓:匿名使用者

1、用字串分隔:

using system.text.regularexpressions;

string str="aaajsbbbjsccc";

string sarray=regex.split(str,"js",regexoptions.ignorecase);

foreach (string i in sarray) response.write(i.tostring() + "

");輸出結果:

aaabbb

ccc2、用多個字元來分隔:

string str="aaajbbbscccjdddseee";

string sarray=str.split(new char[2] );

foreach(string i in sarray) response.write(i.tostring() + "

");輸出結果:

aaabbb

cccddd

eee3、用單個字元來分隔:

string str="aaajbbbjccc";

string sarray=str.split('j');

foreach(string i in sarray) response.write(i.tostring() + "

");輸出結果:

aaabbb

string arr = str.split("o");

這是一個具有語法錯誤的語句,split 的 separator 引數應該是 char 或 string,不應是字串。正確的示例:

string str = "technology";

char separator = ;

string arr = str.split(separator);

string.split 方法有6個過載函式:

程式**

1) public string split(params char separator)

2) public string split(char separator, int count)

3) public string split(char separator, stringsplitoptions options)

4) public string split(string separator, stringsplitoptions options)

5) public string split(char separator, int count, stringsplitoptions options)

6) public string split(string separator, int count, stringsplitoptions options)

下邊我們通過一些例項來說明下怎麼使用(以下string words = "1,2.3,,4";):

1. public string split(params char separator)

程式**

string split = words.split(new char );//返回:

string split = words.split(new char );//返回:

2. public string split(char separator, int count)

程式**

string split = words.split(new char , 2);//返回:

string split = words.split(new char , 6);//返回:

3. public string split(char separator, stringsplitoptions options)

程式**

string split = words.split(new char , stringsplitoptions.removeemptyentries);//返回: 不保留空元素

string split = words.split(new char , stringsplitoptions.none);//返回: 保留空元素

4. public string split(string separator, stringsplitoptions options)

程式**

string split = words.split(new string , stringsplitoptions.removeemptyentries);//返回: 不保留空元素

string split = words.split(new string , stringsplitoptions.none);//返回: 保留空元素

5. public string split(char separator, int count, stringsplitoptions options)

程式**

string split = words.split(new char , 2, stringsplitoptions.removeemptyentries);//返回:

不保留空元素

string split = words.split(new char , 6, stringsplitoptions.none);//返回: 保留空元素

6. public string split(string separator, int count, stringsplitoptions options)

程式**

string split = words.split(new string , 2, stringsplitoptions.removeemptyentries);//返回:

不保留空元素

string split = words.split(new string , 6, stringsplitoptions.none);//返回: 保留空元素

需要注意的是沒有過載函式public string split(string separator),所以我們不能像vb.***那樣使用words.split(","),而只能使用words.

split(',')

C中字串轉換為byte型陣列,C中如何將byte轉化為字串

1 函式getbytearray返回轉換 後的位元組陣列,完整程式如下 class program b console.writeline public static byte getbytearray string shex 返回位元組陣列 return bytlist.toarray 2 執行結...

c中字元陣列和字串類的區別

唯一的區別就是字串末尾有一個 0 面字元陣列是沒有的.char ch1 hello 該串有6個字元,5個可見字元,因為是串,所以末尾自動加上 0 共六個 char ch2 這樣寫就成了陣列.是確確實實的5個字元 c語言字串陣列和字元陣列有什麼區別?這個是字元陣列。c語言字元陣列和字串的區別,字元陣列...

C如何用長度來切分字串陣列,c如何把字串陣列分割成一個一個值

是字串分割陣列吧!如果有明顯的特徵就好辦!string s string useragent www 111111 3333332 s useragent.split new char 沒有明顯特徵,有擷取規律可以用擷取字串和for迴圈配合!string imei 1001100210031004 ...