c裡如何在字串內查詢所有子字串所在的位置?並儲存到

2021-05-25 13:59:49 字數 1952 閱讀 3753

1樓:匿名使用者

**其實很簡單,bai

用一個while迴圈既du可以:ilistlist = new list(); // arraylist list = new arraylist();

string a = "ssddxx等級

zhi:12kkkcxc12kkk等級:31sxsd1xd等級:52kkkcsdfsdf2k等級:44";

string b = "等級";

int pos = a.indexof(b);

while(pos > -1)

/*foreach(int i in list)*/

2樓:匿名使用者

在php中使用 explode() 方法可以得到 等級: 之前的字串並轉入陣列

例如$c=explode("等級專:","ssddxx等級:12kkkcxc12kkk等級:31sxsd1xd等級:52kkkcsdfsdf2k等級:44");

echo $c[0]; //ssddxx

echo $c[1]; //12kkkcxc12kkkecho $c[2]; //31sxsd1xdecho $c[3]; //52kkkcsdfsdf2k相信.net 也是如屬此 可以這樣區自字串,希望對你有所幫助

3樓:

listsubindex = new list();

string a = "ssddxx等級

baidu:12kkkcxc12kkk等級:31sxsd1xd等級:52kkkcsdfsdf2k等級:44";

int ii = a.indexof("等級");

while (ii >= 0 && ii < a.length)int arrindex = subindex.toarray(); //你要zhi的dao陣列

4樓:匿名使用者

「等級:xx」這樣?數字兩位嗎?

5樓:匿名使用者

這個不太好分析,

ssddxx等級:12kkkcxc12kkk等級:31 那個12可以分開來 等級為1 2kkkcxc 或者等級為12 kkkcxc 你說呢

6樓:

這個問題適合用正則來解決

c#裡面怎麼把一個字串逐個放入一個陣列中?

7樓:匿名使用者

system.string自帶有tochararray方法,可以直接將字串轉為char陣列,也就是例如

string str = "hello, world";

char chars = str.tochararray();

8樓:匿名使用者

你的意思是 比如 hello這個字串?陣列是h,e,l,l,o?

那就可以用string.mid(i,1)函式。

9樓:匿名使用者

用for 或while迴圈語句 逐個對陣列元素賦值

10樓:匿名使用者

string s="abcde";

char t[100];

int i;

for(i=0;s.length;i++)t[i]=s[i];

t[i]=0;

11樓:

string s="abcde";

char array = new char[s.length];

for(int i=0;i < s.length; i++)array[i]=s[i];

array[i] = '\0';

或者string str= " ,.:";

char array= str.tochararray();參見:

c語言輸入字串並計算字元長度,如何在c語言中計算字串長度

include include include int main printf 字串為 s,字串的長度為 d a,i system pause 這程式沒什麼大問題啊,除了一處語法錯誤,我已經改過來了 直接用strlen a 函式就可以了。如何在c語言中計算字串長度 c語言的字串是由字元陣列形式儲存的...

c 中,輸入兩個字串,怎樣在串中查詢並刪除串,並且是不區分大小寫的查詢

include 字串匹配,在主串中刪除子串int main str2 512 scanf s str1 主串scanf s str2 子串int len1 length str str1 int len2 length str str2 int count 0 匹配次數int index 10 子串...

c語言中計算字串長度的程式,如何在c語言中計算字串長度

函式是 strlen 要包含 標頭檔案 string.h 使用方法 int nlen char str hello world nlen strlen str nlen 就是字串str的長度啦 c語言經典例子之計算一個字串的長度 include include void main 執行結果 inpu...