indexof

Uncaught TypeError: Undefined is not a function on indexOf

人走茶凉 提交于 2019-12-03 15:44:30
问题 I currently have this code to check the website URL GET options for a specific ID, but whenever this code is run, I get a weird error: Uncaught TypeError: Undefined is not a function Here is my code: <script language="JavaScript"> var familyid = "id=8978566"; var corporateid = "id=8978565"; if(window.location.indexOf(familyid) === -1) { document.write("Family ID not found"); } </script> It would be awesome if i could get some guidance on this issue... I couldn't find similar issues using the

Why is this List<>.IndexOf code so much faster than the List[i] and manual compare?

岁酱吖の 提交于 2019-12-03 13:04:39
I'm running AQTime on this piece of code, I found that .IndexOf takes 16% of the time vs close to 80% for the other piece... They appear to use the same IsEqual and other routines. Called 116,000 times inserting 30,000 items. None of the List<> objects gets over 200 elements. (I may be using AQTime incorrectly, I'm looking into this) class PointD : IEquatable<PointD> { public double X, Y, Z; bool IEquatable<PointD>.Equals(PointD other) { return ((X == other.X) && (Y == other.Y) && (Z == other.Z)); } } class PerfTest { readonly List<PointD> _pCoord3Points = new List<PointD>(); public int

Hack to convert javascript number to UInt32

久未见 提交于 2019-12-03 12:18:46
Edit: This question is out of date as the Polyfill example has been updated. I'm leaving the question here just for reference. Read the correct answer for useful information on bitwise shift operators. Question: On line 7 in the Polyfill example of the Mozilla Array.prototype.indexOf page they comment this: var length = this.length >>> 0; // Hack to convert object.length to a UInt32 But the bitwise shift specification on Mozilla clearly states that the operator returns a value of the same type as the left operand: Shift operators convert their operands to thirty-two-bit integers and return a

indexOf and lastIndexOf in PHP?

戏子无情 提交于 2019-12-03 10:37:28
问题 In Java, we can use indexOf and lastIndexOf . Since those functions don't exist in PHP, what would be the PHP equivalent of this Java code? if(req_type.equals("RMT")) pt_password = message.substring(message.indexOf("-")+1); else pt_password = message.substring(message.indexOf("-")+1,message.lastIndexOf("-")); 回答1: You need the following functions to do this in PHP: strpos Find the position of the first occurrence of a substring in a string strrpos Find the position of the last occurrence of a

How to get the Index of second comma in a string

落花浮王杯 提交于 2019-12-03 10:25:07
I have a string in an Array that contains two commas as well as tabs and white spaces. I'm trying to cut two words in that string, both of them before the commas, I really don't care about the tabs and white spaces. My String looks similar to this: String s = "Address1 Chicago, IL Address2 Detroit, MI" I get the index of the first comma int x = s.IndexOf(','); And from there, I cut the string before the index of the first comma. firstCity = s.Substring(x-10, x).Trim() //trim white spaces before the letter C; So, how do I get the index of the second comma so I can get my second string? I really

strange string.IndexOf behavour

守給你的承諾、 提交于 2019-12-03 08:09:52
I wrote the following snippet to get rid of excessive spaces in slabs of text int index = text.IndexOf(" "); while (index > 0) { text = text.Replace(" ", " "); index = text.IndexOf(" "); } Generally this works fine, albeit rather primative and possibly inefficient. Problem When the text contains " - " for some bizzare reason the indexOf returns a match! The Replace function doesn't remove anything and then it is stuck in a endless loop. Any ideas what is going on with the string.IndexOf? Ah, the joys of text. What you most likely have there, but got lost when posting on SO, is a "soft hyphen".

String.indexOf gives a value one less than expected

柔情痞子 提交于 2019-12-02 23:53:03
问题 I do not understand the behaviour of the String.index Of method. String peter = "Peter Piper picked a peck of pickled pepper"; System.out.println("The number of p in the sentence is, " + peter.indexOf('p')); Why is the output of p 8 and not 9? There are 9 P's in the sentence. 回答1: Indexes are zero-based: ↓ Peter Piper picked a peck of pickled pepper 111111111122222222223333333333444 0123456789012345678901234567890123456789012 ↑ The first p is at index 8 . From the javadoc of indexOf():

While loop doesn't run a indexOf search

拟墨画扇 提交于 2019-12-02 23:37:20
问题 I'm trying to find out how many times one string appears in another. For my testing, I'm using "ea" for wordOne and "Ilikedthebestontheeastbeachleast" for wordTwo. My output is returning 0 for my "appearance" variable, which should store how many times "ea" appears in wordTwo. Here's the relevant code section: int wordTwoLength = wordTwo.length(); System.out.println(wordTwoLength); while (wordTwoLength > 0) { positionCount = wordTwo.indexOf(wordOne, positionCount); appearances = appearances++

While loop doesn't run a indexOf search

为君一笑 提交于 2019-12-02 14:41:02
I'm trying to find out how many times one string appears in another. For my testing, I'm using "ea" for wordOne and "Ilikedthebestontheeastbeachleast" for wordTwo. My output is returning 0 for my "appearance" variable, which should store how many times "ea" appears in wordTwo. Here's the relevant code section: int wordTwoLength = wordTwo.length(); System.out.println(wordTwoLength); while (wordTwoLength > 0) { positionCount = wordTwo.indexOf(wordOne, positionCount); appearances = appearances++; wordTwoLength = (wordTwoLength - positionCount); } System.out.println(appearances); What do you mean

Array.binarySearch returning wrong data

雨燕双飞 提交于 2019-12-02 14:31:07
问题 I am trying to validate password and username using array and the array.BinarySearch function. The first two user names in the array: bradley and john are returning the correct position using the function 0 and 1. However when I try to validate the last two strings in the array jim and clarke, the binarySearch function returns the username is located at position -2 in the array both times which is causing validation to fail. Any ideas? String[] names = {"bradley","john","jim","clarke"};