FAQ Database Discussion Community


Finding text in string, storing it on array and displaying it

javascript,arrays,for-loop,indexof
I am trying to find a strings in a string content and pushing the found content letter by letter in an array and display all the found content in html. But it seems like something wrong with the for loop (do not run it crashes). What would be the best...

Array.indexOf for list of lists is not working

javascript,indexof
I have a list of lists which comes from the server in ajax response has following structure: var mapping = [ //response.mapping ["userOne", 1], ["userTwo", 2], ["userthree", 3], ["userfour", 4], ["personOne", 1], ["personTwo", 2], ["personOne", 3], ]; As the list will be constant forever, which will have only 7 elements...

Is there a better way to divide this string into substrings?

java,append,substring,indexof,lastindexof
I am trying to extract the "first_name" and "last_name" from a long string of information that look like this: { "123123123": { "id": "12321312****", "email": "***************", "first_name": "Marcus", "gender": "male", "last_name": "Bengtsson", "link": "https://www.facebook.com/app_scoped_user_id/123123123/", "locale": "en_EN", "middle_name": "Peter", "name": "Marcus Peter Bengtsson" } } The way I do it (which...

Can IndexOf be used to search for two or more alternate strings in a TStringList in Delphi?

delphi,indexof,tstringlist
I have used IndexOf() in order to extract the index of a TStrinList in Delphi 2005. At the moment it only searches for one string but I would like it to search for alternative strings. For example, to search for 'String A', 'String B' or 'String C' and give me...

A Smarter Way to Learning JavaScript: Chapter 23 - Strings: Finding Segments

javascript,slice,indexof
I am working through the chapters and exercises for A Smarter Way to Learning JavaScript, Chapter 23 covers Strings: Finding Segments using indexOf and lastIndexOf methods. In the example a second variable firstChar is assigned the value of a variable text which contains a string "World War II". The objective...

How to get indexOf of matching chracters

javascript,indexof
I want to get indexOf of all occurring characters. For Example, I have a variable a var a = "aabaaababaa"; I want to get indexOf for all characters in a I tried: for(i = 0; i < a.length ;i++){ var len = a.indexOf(a); console.log(len); } But it returns indexOf for...

(jQuery) Select element into TD and filter values with only digits

javascript,jquery,html,indexof
I have a table with a lot td ".numbers" like this: <tr><td class="numbers">12345</td></tr> <tr><td class="numbers">6789</td></tr> <tr><td class="numbers">123%</td></tr> I need to select only TD values without "%" and other chars. Note: i cannot remove class "numbers" because is automatically generated. This is not working: $.each($(".numbers"), function( index, value ) { if...

How to avoid the StringIndexOutOfBoundsException if a substring is not in my original String?

java,string,substring,indexof
I have something like: String idCodice = cessionarioCommittente.substring( cessionarioCommittente.indexOf("<IdCodice>") + 10, cessionarioCommittente.indexOf("</IdCodice>")); used to extract the value inside the tag of an XML document represented by the content of the cessionarioCommittente String variable. The problem is that the <IdCodice> tag might not exist in the cessionarioCommittente String. So in this...

Removing an element from an array of Object

javascript,mongodb,meteor,indexof
I'm building a live notification system with Meteor, but as I've never done this before, I'm certainly tricking to get something that works. I have a <ul> list of notifications. I defined an event clicking on the <a class="notif-link"> that each <li> contains. My notifications have an ID, a type,...

JavaScript - find text in URL by position

javascript,jquery,indexof
This should be pretty easy but I'm struggling. I have a button that fires a function. I want an alert to fire as well that tells me which page the user was on. www.whatever.com/thispage1/whatever www.whatever.com/thispage2/whatever www.whatever.com/thispage3/whatever So after my button is clicked, I want an alert that reads back "thispage1"...

indexOf causing error in IE; working in other browsers

javascript,internet-explorer,indexof
EDIT: I'm super confused. I have a local copy of the webpage, in which I added the 'indexOf' function to the javascript file. This page is working. However, the page on the live site, which I have pushed my changes to, is still getting the indexOf error. Furthermore, another page...

Java ArrayList indexOf returns -1

java,arraylist,equals,indexof
I have a strange problem with my code. Heres the code I test the Chunk class with: List<Chunk> chunks = new ArrayList<Chunk>(); chunks.add(new Chunk(1,1,1)); System.out.println(chunks.indexOf(new Vector3i(1, 1, 1))); And here is the Chunk class' equals method: public boolean equals(Object object) { System.out.println("Test _1_"); if (object != null && object instanceof...

Complex Hashmap ArrayList Generator

java,arraylist,hashmap,indexof
Here's some code: ArrayList<String> List = new ArrayList<>(); Map<String, List<String> > map = new HashMap<String, List<String>>(); List.add("stringA"); List.add("stringB"); List.add("stringC"); for(int i = 0; i<List.size();i++){ String key = List.get(i); List<String> value = new ArrayList<String>(); map.put(key, value); } This code takes whatever is in the ArrayList, loops through it, adds it to...

jQuery - Using indexOf() with match()

jquery,regex,url,match,indexof
I am currently working on an user script made for YouTube using Firefoxs addon 'Greasemonkey' and came across a deadend.. Is it possible to check the url whether or not the url contains a specific string? I tried using indexOf() along with match() since I want it to check the...

Find item in array with indexOf

javascript,jquery,indexof
I have a problem with 'indexOf'. When i pass a numerical value in argument, it works, but not with a variable: $.ajax({ url: 'bdd.php', type: 'POST', data: {'jsonNomCommune': jsonNomCommune, 'client': client}, success: function(data) { data = JSON.parse(data); listClients= data.clients; listProspects = data.prospects; $('#tableCSV tbody tr ').each(function(){ var id = $(this).attr('id');...

indexOf(“http”) matches on http and https

javascript,jquery,indexof
I have the following code, var protocol = jQuery('script[src*="kaltura"]').attr("src"); protocol.toLowerCase().indexOf("http"); The problem is that indexOf is matching on http and https. How can I only get it to match on http?...

How search a datum in ArrayList with indexOf [closed]

java,search,arraylist,stringbuilder,indexof
How search a datum in ArrayList with indexOf ArrayList<StringBuilder> state = new ArrayList<StringBuilder>(); state.add(new StringBuilder("A")); state.add(new StringBuilder("B")); state.add(new StringBuilder("C")); state.add(new StringBuilder("D")); System.out.println(state.indexOf(new StringBuilder("B"))); //Out: -1 ...

TextBox Indexof and LastIndexOf

c#,textbox,indexof,lastindexof
Because TextBox doesn't have a find function, I've created and modified my own version of it to my needs. I've created to functions. One for Search Next and another for Search Previous My problem is that: If my search term is more than 1 character long and I've searched for...

indexOf returns -1 for the first letter of a word

javascript,indexof
I'm trying to make a simple hangman game. I logged the word to the console what should be guessed (this will be removed when the game is finished.) Now I'm trying to make the player guess if the letter is in the word, if it is, it should reveal itself....

Finding a specific string in array of strings

javascript,arrays,string,for-loop,indexof
In an array of strings, a loop returns false if it finds that one of the strings is not what we are looking for. If it doesn't find an unmatching string, the array is correct and it should return true. It keeps returning false even when the array has no...

DART: indexOf() in a list of Instances

list,dart,indexof
How to obtain the index of one Instance in a List? class Points { int x, y; Point(this.x, this.y); } void main() { var pts = new List(); int Lx; int Ly; Points pt = new Points(25,55); // new instance pts.add(pt); int index = pts.indexOf(25); // Problem !!! How to...

How to find the index of the Object(that has its own parameters) in arraylist with using indexOf method

java,arraylist,collections,indexof
I have the ArrayList of the objects Song. Each Song has its own parameters, title, composer, duration,. I'm trying to write the method that will be looking for the title of the object Song and will give me the INDEX of the object in ArrayList with this parameter. songs is...

_.indexOf() `item !== item` - what is its purpose?

javascript,underscore.js,indexof
Looking into Underscore.js code and more specifically into _.indexOf() function (find code with comments here) _.indexOf = function(array, item, isSorted) { var i = 0, length = array && array.length; if (typeof isSorted == 'number') { i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; } else...

Get element starting with letter from List

java,android,list,indexof
I have a list and I want to get the position of the string which starts with specific letter. I am trying this code, but it isn't working. List<String> sp = Arrays.asList(splited); int i2 = sp.indexOf("^w.*$"); ...

How do I use C#'s IndexOf when strange characters are in the string

c#,indexof
Below is what the text looks like when viewed in NotePad++. I need to get the IndexOf for that peice of the string. for use the the below code. And I can't figure out how to use the odd characters in my code. int start = text.IndexOf("AppxxxxxxDB INFO"); Where the...

Working click event in current index with jquery

jquery,html,onclick,click,indexof
I have code below in HTML <ul> <li>Item1</li> <li>Item2</li> <li>Item3</li> <li>Item4</li> <li>Item5</li> <li>Item6</li> <li>Item7</li> <li>Item8</li> </ul> i want write one code for all "li" tag in click event! i can get index width this code $("li").click(function () { var current = $(this).parent().children().index(); } but i can't do any thing with...

Search into divs

javascript,search,indexof
I found this post How to perform a real time search and filter on a HTML table and I would like to adapt it to search in divs. Html : <input type="text" id="search" placeholder="Type to search"> <table id="table"> <tr> <div class="panel panel-default"> <!-- Default panel contents --> <div class="panel-heading">Panel 1</div>...

Remove element if anchor uses Javascript: void(0)

javascript,jquery,indexof
<a class="slicknav_item" href="home">Home<span></span></a> <a class="slicknav_item" href="about">About<span></span></a> <a class="slicknav_item" href="javascript: void(0)">Services<span></span></a> if ($('.slicknav_item').attr('href').indexOf('javascript: void(0)') > 0) { $('.slicknav_item span').remove(); } Using the above code, I'm trying to find anytime ".slicknav_item" contains "javascript: void(0)" as the href, and remove the element ".slicknav_item span"...

Return ternary operator in JavaScript reduce

javascript,arrays,indexof,reduce
I have a data structure like this: var example = [ { name: "item1", year: 2013, value: 100 }, { name: "item1", year: 2012, value: 97 }, { name: "item3", year: 2013, value: 93 }, { name: "item3", year: 2012, value: 91 }, { name: "item2", year: 2012, value: -6...

how to get array key from string array in java [Solved]

java,arrays,indexof
I have a string array that has duplicate value, then I remove the duplicate. Now, I need to get the array key from the result before and store it to new int array. I do not know how it will work in Java, since I search java doesn't provide array...

How to check if value exists in array using javascript

javascript,arrays,indexof
I have an an array in the form: "localValues" : [ { "localValId" : "8KfbEozjdQYAefuHF", "localProductCode" : "291105300", "localMarkupVal" : "2.8", "localMembersPrice" : "3344" }, { "localValId" : "qdCY6Kkvc7e8m4yxw", "localProductCode" : "291105300234", "localMarkupVal" : "2.8432", "localMembersPrice" : "3344333" }, { "localValId" : "i827Eve8zBexRSTSP", "localProductCode" : "291105300", "localMarkupVal" : "2.8432", "localMembersPrice"...

List object IndexOf returning -1. How?

c#,list,indexof
This is very baffling to me. Somehow the IndexOf(string) method of my List<string> object is returning -1 even though the value is CLEARLY in the List. protected readonly List<string> validPrefixes = new List<string>() { "01", "02", "03", "FE", "E1", "E2", "E3" }; string prefix is "01" validPrefixes index 0 is...

Using indexOf() to search array inside ng-repeat

javascript,angularjs,indexof
I'm try to search an array of id's [1, 2, 3] with indexOf() inside an ng-repeat loop, but probably because of a wrong data type, it doesn't work. <li ng-repeat="member in message.members"> Member ID: {{ member.id }} <span ng-if="message.read_by.indexOf(member.id) > -1">Read</span> </li> The array message.read_by = [1, 2, 3] and...

Javascript - How to find specific string using .indexOf instead of just the beginning

javascript,string,indexof
I'm trying to run some code if a string is found in the users URL. However I only want it to run if there is nothing else following the string. The string appears at the end of the URL like this. http://shop.com/?searchTerm=bread My code: if (window.location.search.indexOf('searchTerm=bread') > -1) { do...

Count number of consonants in a string

c,string,indexof
Another starter question. int counterConstant; int x; for(x = 0; x<20; x++){ if("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSVWXYZ".IndexOf(tempString[x]) >= 0){ counterConsonant++; } } But I get an error: "error: member reference base type 'char [42]' is not a structure or union" Is there another way I could do this? (I'm doing this inside a for...

Performance of IndexOf(char) vs Contains(string) for checking the presence of a character in a string

c#,string,contains,indexof
I want to know if string.IndexOf(char) is faster than string.Contains(string). Intention is to check if a single character is present in a string. I know that as per requirement I should use string.Contains(string) but that is not the point of this question. I did try to disassemble mscorlib.dll in an...

indexOf keeps returning -1 Javascript

javascript,arrays,while-loop,indexof
For the life me of I can't figure out why indexOf cant find the number in the array. It keeps returning -1. My goal is to ban a noun and put it into a ban array list, the list must be unique. So each element in the array must be...

What is the best way to check whether a particular string is present in a hostname or not?

java,string,indexof
I have a hostname like this p-desktop-1234565.teck.host.com which I need to check whether it is in teck domain/datacenter or not. Any hostname will be in teck domain, if it has .teck. in the hostname. As an example we might have machine in other datacenters (dc1, dc2, dc3) so there hostname...

How to get the index of a specific item in an ArrayList?

java,object,arraylist,get,indexof
I fill up an Array List with some numbers and want to find a specific number that is in the Array List and get its position (the index) in my Array List. Any example would be great! for example ProClon.indexOf(spro.getId(id)); ...

Javascript selecting to save one index of split()

javascript,string,split,indexof
I have a value - toggle-save_2 I want to extract the 2 part. The part after the underscore will always be what i need but the length of the former part, which in this case is toggle-save_, may vary (eg. notoggle-val_45). Though this length may vary it will always be...