2012年11月12日 星期一

Javascript search string

1. Problem:
   There are kind of search string function in javascript. At first
   we can attract by  search() method, but when we use it to search dot "."  
   information such as judge the upload file is ".jpeg" suffix,  it will return 0.


2. Why:
   Because argument of search()  is regular expression, I avoid it and use
   indexOf() method replace it. And it will work correct


3. Example:
strA = "myPic.jpeg"
strA.search(".");
result: 0
strA.indexOf(".");
result: 5



Reference:
Like problem
string method

沒有留言:

張貼留言