不卡AV在线|网页在线观看无码高清|亚洲国产亚洲国产|国产伦精品一区二区三区免费视频

學(xué)習(xí)啦 > 學(xué)習(xí)英語 > 專業(yè)英語 > 計算機英語 > c語言indexof的用法有哪些

c語言indexof的用法有哪些

時間: 澤燕681 分享

c語言indexof的用法有哪些

  小編整理了c語言 indexof的用法。希望對你有幫助哦!

  IndexOf()

  查找字串中指定字符或字串首次出現(xiàn)的位置,返首索引值,如: str1.IndexOf("字"); //查找“字”在str1中的索引值(位置)

  str1.IndexOf("字串");//查找“字串”的第一個字符在str1中的索引值(位置) str1.IndexOf("字",start,end);//從str1第start+1個字符起,查找end個字符,查找“字”在字符串STR1中的位置[從第一個字符算起]注意:start+end不能大于str1的長度

  indexof參數(shù)為string,在字符串中尋找參數(shù)字符串第一次出現(xiàn)的位置并返回該位置。如string s="0123dfdfdf";int i=s.indexof("df");這時i==4。

  如果需要更強大的字符串解析功能應(yīng)該用Regex類,使用正則表達式對字符串進行匹配。

  indexof() :在字符串中從前向后定位字符和字符串;所有的返回值都是指在字符串的絕對位置,如為空則為- 1

  string test="asdfjsdfjgkfasdsfsgfhgjgfjgdddd";

  test.indexof(’d’) =2 //從前向后定位 d 第一次出現(xiàn)的位置

  test.indexof(’d’,5,2) =6 //從前向后定位 d 從第5 位開始查,查2位,即從第5位到第7位;

  lastindexof() :在字符串中從后向前定位字符和字符串; 用法和 indexof() 完全相同。

  下面介紹 IndexOfAny ||lastindexofany

  他們接受字符數(shù)組做為變元,其他方法同上,返回數(shù)組中任何一個字符最早出現(xiàn)的下標位置 如下

  char[] bbv={’s’,’c’,’b’};

  string abc = "acsdfgdfgchacscdsad";

  Response.Write(abc.IndexOfAny(bbv))=1 Response.Write(abc.IndexOfAny(bbv, 5))=9 Response.Write(abc.IndexOfAny(bbv, 5, 3))=9 lastindexofany 同上。

  substring() 用法

  string a="aadsfdjkfgklfdglfd"

  a.substring(5) //截取從第五位以后的所有字符串 a.substring(0,5) //截取從第0到第5 以后的所有字符串

  var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);

  C# code

  privatevoid btnLog_Click(object sender, EventArgs e)

  {

  //登陸判斷

  string userName = this.texName.Text; string userpwd = this.texPwd.Text; string userCard=this.texCombo.Text;

  try {

  int id = Convert.ToInt32(userName);

  string getpwd = Employee.SelectByID(id).Password; if (userName == getpwd && userCard != "--請選擇--")

  {

  //登陸正確

  LoginInf.userName = userName; LoginInf.userPwd = userpwd; LoginInf.userCad = userCard;

  //關(guān)閉登陸框轉(zhuǎn)到首頁

  this.Hide();

  new Home().ShowDialog();

  this.Close(); }

  else

  {

  //登陸失敗

  MessageBox.Show("登陸失敗");

  var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);

  } } catch {

  MessageBox.Show("登陸失敗!!!");

  return; }

  }

430815