Questions tagged [indexof]

indexof is a method in programming languages like Java, C#, JavaScript, etc. that returns the first occurrence of a letter in a string, or the first occurrence of an element in a list.

indexof returns the first occurrence of a letter or a substring in a string, or the first occurrence of an element in a list.

1975 questions
0
votes
2 answers

Perl: find the last occurrence of the char "\"

I want to strip the path from a file string like this: Root\ToOrganization\Service_b37189b3-8505-4395_Out_BackOffice.xml I am trying to find the index of the last occurrence of "\" so I can use substring up to there. but I can't use the char "\" in…
David Gidony
  • 1,243
  • 3
  • 16
  • 31
0
votes
2 answers

how to use indexOf proper to check if something is in the array

I want to check in this guessing game if the color the user inputs is in the array list or not. but when u put a color that is in the list it keeps saying it isn't var guess_input; var target; var colors = ["blue", "cyan", "gold", "gray", "green",…
0
votes
1 answer

JavaScript Empty Array indexOf

I went through some JS code last day, but I couldn't understand. Here is the code var data = { name : 'Mr John', age : '29', location : 'New York', profession : 'Accoutant' }; var allowedNull = []; for (var i in data) { …
noob
  • 641
  • 1
  • 6
  • 21
0
votes
1 answer

If (name of array) from input value IndexOf specific value not working

I have html form where user enter a date. I need script what recognize if entered date is equal to some date from array ("takeOverArray["tz27092015", "tz21102015", "tz26092015"]") (that's working) but.. Every array value (["tz27092015",…
0
votes
4 answers

Matching string with things from array in a for loop with indexOf, error

I'm having a little problem with finding and displaying strings from an array. Haven't done any sort of code in years so I'm kind of rusty. My problem is this: Say I have an array like this: var titles = ["0","Little Mouse", "1","Shaman Disciple",…
Deda
  • 3
  • 1
0
votes
5 answers

Job interview test - finding the index of the first of two chars to appear in a string

I just had an online interview and was asked a neat question. Thought I would share it with the community, along with my answer. See if you think my answer is correct and if not - how would you improve on it? I think this could benefit any people…
Amos Bordowitz
  • 474
  • 6
  • 19
0
votes
4 answers

IndexOf in an array that contains attributes

I ask my question differently : I'm using angular/Javacript and i want to know if a value exist in an array or not. Here's my code : var source = [1, 2, 3 , 4 , 5]; var cities = [{ city: 4 }, { city: 6 }, { city: 8 }]; …
user708683
  • 500
  • 3
  • 9
  • 26
0
votes
5 answers

Trouble with strings and indexOf

If the user types yes, I am trying to create a list(receipt) of everything the user entered between the commas. For example: cat, dog, fish would return: cat dog fish on separate lines. Would I use indexOf? if (language.equals("English"))…
Shajinator
  • 25
  • 5
0
votes
1 answer

Find the position of a character in a string?

I need to find the position of a character in a string and to return an Int for further calculation. let idx = cycleOrder.characters.indexOf(charInput) This gives me the index, but how do I get this into an Int? I tried: intIdx = Int(idx) but that…
brandenwagner
  • 138
  • 1
  • 5
  • 20
0
votes
3 answers

Replace letters with *

Making a hangman style of game I have the random word now. How do I replace the letters of the word with an asterix * so that when the program starts the word is shown as *. I assume that when someone inputs a letter for the hangman game you get the…
Jay W
  • 1
  • 2
0
votes
3 answers

how do i check the data in an array with indexOf in java

i'm fairly new to java and i'm trying to use indexOf to check if a persons name ends with the letters in the array and output a word it rhymes with. Where am i going wrong? e.g. Dean ends in "ean" so it rhymes with green. Thanks guys String []…
tim roth
  • 3
  • 3
0
votes
1 answer

C# Replace Emoticons In Html String

I have the following method for replacing emoticons in a string using C# public static string Emotify(string inputText) { var emoticonFolder = EmoticonFolder; var emoticons = new Hashtable(100) { {":)",…
YodasMyDad
  • 9,248
  • 24
  • 76
  • 121
0
votes
0 answers

JS indexOf Always Returns -1

I've got an array thats being built from a CSV file, the array builds just fine: 0: Array[80] 0: "AM" 1: "AX" 2: "AR" 3: "JR" 4: "AC" 5: "AF" etc... I'm then trying to verify that a string taken from a text input appears…
0
votes
1 answer

object value matches any in array indexOf

I am currently writing a bit of a side project. This should be quite simple. I have an array of values that looks like values = ["Snow","Rain"]; I am trying to check an object property value against all values in the array. If there is only one…
0
votes
2 answers

Assign each index argument different function

I have this code. $('#my-container-div').on('onAlbumLoad', function(event, index) { ... }); I need to assign a different function to each instance of index and am at a loss. In non-coder terms, I'm looking for: If index equals 0 do this, if index…
macmike78
  • 5
  • 2