[JavaScript] Javascript 检查子字符串是否存在于字符串中 →→→→→进入此内容的聊天室

来自 , 2020-05-28, 写在 JavaScript, 查看 201 次.
URL http://www.code666.cn/view/b448d829
  1. var strnew="Hello Raghu How are u"
  2.  
  3. Checking existence in entire string
  4. ====================================
  5.  
  6. if(strnew.indexOf("Raghu") != -1 )
  7. {
  8.     alert("Exists");
  9. }
  10.  
  11. Checking existence at the end of string
  12. ===============================================
  13. For example, variable result1 in the following example is assigned
  14. the value of true because the word "Ishmael" appears at the end of
  15. the string. Variable result2 is assigned a value of false because
  16. "Raghu" doesn't appear at the end of the string.
  17. ---------------------------------------------------------------------
  18.  
  19. result1 = /Raghu$/.test("Call me Raghu");
  20. result2 = /Raghu$/.test("Call me Raghu. Some years ago");
  21.  
  22. Checking existence in the begining of string
  23. =====================================================
  24. In the following example, variable result1 is assigned the value
  25. of true because the word "Birds" appears at the beginning of the
  26. string. Variable result2 is assigned the value of false because
  27. "Birds" doesn't appear at the beginning of the string.
  28. -------------------------------------------------------------------
  29.  
  30. result1 = /^Birds/.test("Birds fly");
  31. result2 = /^Birds/.test("Big Birds fly");
  32. //javascript/166

回复 "Javascript 检查子字符串是否存在于字符串中"

这儿你可以回复上面这条便签

captcha