Split 分段取文字裡的值

2022-03-20 10:31:40 字數 1247 閱讀 6281

單個字元隔開

例項:頁面**:

<

body

>

<

form

id="form1"

runat

="server"

>

<

div>

div>

form

>

body

>

後台**:

protected

void page_load(object sender, eventargs e)

protected

void button1_click(object sender, eventargs e)

);//獲取文字以逗號隔開的值個數(例如:張三,李四)那麼split.length.tostring()==2

textbox2.text=split.length.tostring();

//獲取第乙個值(如張三)

textbox3.text=split[0].tostring();

//獲取第二個值(如李四)

textbox4.text=split[1].tostring();

}

當文字框裡輸入的結果是「張三,」這時系統會預設有乙個空值,也就是說都好分割開的個數是2;那麼我們應該如何忽略這個空值呢?

string split = textbox1.text.split(new char ,stringsplitoptions.removeemptyentries);

//加上這麼一句話stringsplitoptions.removeemptyentries就可以了!

//(例如:張三,)split.length.tostring()的值為1

用多個字元來分隔:

string time="10時48分66秒";

string split = time.split(new char );

string hour = split[0].tostring();

string min = split[1].tostring();

string ss = split[2].tostring();

//求的秒數

int second = int.parse(hour) * 3600 + int.parse(min)*60 + int.parse(ss);

jquery取選項文字值

1 select被選中文字值 jquery可以通過下面的方式取出選項的文字值 work html work nature id option selected text 2 check box被選中文字值 本來想向select一樣如法炮製,但是費了很大勁也沒成功 最後找到乙個解決方案,只是要給che...

正則法則提取文字裡的時間

1 功能概述 實現通過正則法則,來提取乙個文字裡面包含的時間 2 實現思路 1 編寫適合篩選格式的正交法則 如圖實現 年 月 日的篩選 年 月 日 年 月 日 的格式,我們可以更改不同篩選規則,進行不同格式篩選 pattern pattern.compile 0 9 年 0 9 1 9 月 0 9 ...

去除文字裡的html標籤的C 方法

清除文字中html的標籤 protected string clearhtml string content 清除文字中的html標籤 要替換的標籤正規表示式 替換為的內容 要替換的內容 private string zxj replacehtml string patrn,string strre...