indexof.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var str = "abbbagfedcabbba";
  6. WScript.Echo(str.indexOf("abb"));
  7. WScript.Echo(str.indexOf("abb", 1));
  8. WScript.Echo(str.indexOf("abb", 2));
  9. WScript.Echo(str.indexOf("bba", 3));
  10. WScript.Echo(str.indexOf("bba", 4));
  11. WScript.Echo(str.indexOf("xyz"));
  12. WScript.Echo(str.indexOf("bgf"));
  13. WScript.Echo(str.indexOf("acde"));
  14. WScript.Echo(str.indexOf("edca"));
  15. WScript.Echo(str.indexOf(""));
  16. WScript.Echo(str.indexOf("", 11));
  17. var str2 = "\0\0dcba\0";
  18. WScript.Echo(str2.indexOf("\0\0"));
  19. WScript.Echo(str2.indexOf("\0dc"));
  20. WScript.Echo(str2.indexOf("ba\0"));
  21. var str3 = "abb";
  22. WScript.Echo(str3.indexOf("abbbagfedcabbba"));
  23. var str4 = "\u0100\u0111\u0112\u0113";
  24. WScript.Echo(str4.indexOf("\u0112\u0113"));
  25. //implicit calls
  26. var a = 1;
  27. var b = 2;
  28. var obj = {toString: function(){ a=3; return "Hello World";}};
  29. a = b;
  30. Object.prototype.indexOf = String.prototype.indexOf;
  31. var f = obj.indexOf("e");
  32. WScript.Echo (a);