Forum

Yampiz Forum

Sharing let knowledge Spreaded, Reading let spirits growth, Creative let culture extended, Let us
  • 禁止廣告文
  • 知識傳播
  • 閱讀
  • 心靈成長
  • 創作
  • 文化傳承
Forum Dictionary / Programming / 網頁/網站程式 / JavaScript /

找出字串中某一值的位置 indexOf

New Subject
Random
Previous
Next
|
找出字串中某一值的位置 indexOf

php的strpos 以及 javascript的indexOf()
我們常常有機會要去判斷字串裡面是否有某一個字元或字串,在 PHP 裡都是用 strstr 或strpos 來做判斷,但偶爾還是有機會要用到 javascript 來直接判斷。

在 javascript 裡用的是 indexOf 這個函式。

JavaScript indexOf 方法的內容

定義和用法
indexOf() 方法可傳回某個指定的字串值在字串中首次出現的位置。

語法

程式
  1. stringObject.indexOf(searchvalue,fromindex);

參數說明
searchvalue 必需。欲搜尋的字符值。
fromindex 可選的整數值。規定在字串中開始搜尋的位置。它的合法值是 0 到 stringObject.length - 1。如省略此參數,則將從字串的第一個字開始搜尋。

注意:indexOf() 方法有區分大小寫!

  • Keywords : indexOf, javascript, 方法, 搜尋, 位置, strpos, stringObject, searchvalue, fromindex, 語法, 規定, 裡用, 第一, 程式, 用法, 注意, 欲搜尋, 機會要用到, 某一, 整數值
0 0
2010-02-02T03:47:00+0000

學生妹瀨043811 :

!!! The contents has been hidden because it violates policy tactic. !!!
0 0
2019-01-29T16:53:18+0000


  • Now, you can post comments by Facebook Account when your Yampiz account was logout or unvariable. whatever, we suggest to post comment by Yampiz Account to get more bounds to join new events of Heyxu
Comment
 
Verify
  • Auto Platform
    For better browsing experience, it will auto detects your device to display webpage.
  • Bug Report
    Tell us about the idea, problem and errors you found.
  • Comodo Secure
    The sensitive data transmission adopts by SSL-2048 authenticated encryption.
  • Copyright
    © 2009 YamPiz Digital Inc. & Jaby Group. All rights reserved.
  • Revised Version
    V2.2.061
    03 Aug 2023 (GMT+8)