c擷取字串

2022-11-24 14:21:09 字數 1001 閱讀 9900

1樓:匿名使用者

string str1="四川省宜賓市翠屏區";

string result;

result = str1.substring(0, str1.indexof("省"));

console.write(result);

indexof是獲取指定字元在字串中的位置(索引值)。

substring(startindex : int, length : int)它有兩個引數,第乙個是要在指定字串所取字串首字元的位(startindex),第二個是要取字串的長度。

2樓:匿名使用者

indexof("省")獲取 省 這個字元在字串中的位置

3樓:網路劍客

class program

private static string shengfen(string _str)

else if (ch[i].tostring().equals("省"))

}return "無匹配字段";}}

4樓:辜巍文

string str="四川省宜賓市翠屏區";

string split="省市";

string strarray=str.split(split.tochararray);

foreach(string s in strarray)console.writeline(s);

5樓:匿名使用者

使用字串的indexof成員

用法如下:新建windows應用程式,拖進乙個textbox,button和乙個lable控制項,使用預設name

如果仍然不懂到msdn檢視

public partial class form1 : formprivate void button1_click(object sender, eventargs e)//button1的單擊事件

else}}

VC 中如何擷取一段字串,VC 擷取字串問題

樓上的回答是可以但是抄比較麻bai 煩在vc中可以用cstring 類 用reversfind方法 可以du查詢到zhi 最後乙個dao 然後用left方法就可以的到 最後乙個 左邊的所有字串了具體可以檢視msdn的說明,很方便的 char str c tomcat abc txt char str...

這樣用jquery擷取字串得到特定字元

不推薦用正規表示式,建議使用字串的兩個方法 substr或subtring var from abcdefg var to from.substr 1,3 表示從1位開始擷取後面的3個字元,bcd to from.substring 1,3 表示從1位開始擷取到3位,bc 所以你上面的 可以這樣寫 ...

python正規表示式如何擷取字串中間的內容

啟動ipython先導入re模組 這裡我用到了findall全域性匹配,分為兩部分,前面是正則,後面是要匹配的字串 得到乙個元祖 通過變數a 就能列印出想要的字串 在 python 中,我們可以使用內建的 re 模組來使用正規表示式,re 模組提供了不少有用的函式,用以匹配字串,比如 re 模組的一...