indexof

Searching for line of one text file in another text file, faster

旧巷老猫 提交于 2019-12-23 03:27:45
问题 Is there a faster way to search each line of one text file for occurrence in another text file, than by going line by line in both files? I have two text files - one has ~2500 lines (let's call it TxtA), the other has ~86000 lines(TxtB). I want to search TxtB for each line in TxtA, and return the line in TxtB for each match found. I currently have this setup as: for each line in TxtA, search TxtB line by line for a match. However this is taking a really long time to process. It seems like it

jQuery val() indexOf not working

て烟熏妆下的殇ゞ 提交于 2019-12-23 02:48:08
问题 Trying to do something if the input value contains a certain word but this doesn't work: var formMain = $('#MainForm :input[name="Search"]'); if ((formMain).value.indexOf('word') >= 0) { alert('HAS THIS WORD IN IT!'); Example Form: <form onsubmit="return OnSubmitSearchForm(event, this);" action="/searchresults.asp" id="MainForm" name="MainForm" method="post" class="search_results_section"> <input type="hidden" value="word" name="Search"> <input type="hidden" value="" name="Cat"> </form> 回答1:

Getting the number of occurrences of one string in another string

北城余情 提交于 2019-12-22 07:11:01
问题 I need to input a two strings, with the first one being any word and the second string being a part of the previous string and i need to output the number of times string number two occurs. So for instance:String 1 = CATSATONTHEMAT String 2 = AT. Output would be 3 because AT occurs three times in CATSATONTHEMAT. Here is my code: public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word8 = sc.next(); String word9 = sc.next(); int occurences = word8.indexOf(word9

indexOf returning -1 despite object being in the array - Javascript in Google Spreadsheet Scripts

元气小坏坏 提交于 2019-12-22 04:44:06
问题 I am writing a script for a Google Docs Spreadsheet to read a list of directors and add them to an array if they do not already appear within it. However, I cannot seem to get indexOf to return anything other than -1 for elements that are contained within the array. Can anyone tell me what I am doing wrong? Or point me to an easier way of doing this? This is my script: function readRows() { var column = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("Director"); var values = column

Is using a Regular Expression faster than IndexOf?

梦想的初衷 提交于 2019-12-22 03:45:05
问题 I have an app running which looks at items in a queue, then based upon certain keywords a category is applied - then it is inserted into a database. I'm using IndexOf to determine if a certain keyword is present. Is this the ideal way or would a RegEX be faster? There's about 10 items per second being processed or so. 回答1: For just finding a keyword the IndexOf method is faster than using a regular expression. Regular expressions are powerful, but their power lies in flexibility, not raw

Lua - get indexOf string

巧了我就是萌 提交于 2019-12-21 12:37:55
问题 I am stuck with a problem in Lua to check whether the string value is not presented in another string. That's how I likely will do it in Javascript: 'my string'.indexOf('no-cache') === -1 // true but in Lua I'm trying to use string module which gives me unexpected response: string.find('my string', 'no-cache') -- nil, that's fine but.. string.find('no-cache', 'no-cache') -- nil.. that's weird string.find('no-cache', 'no') -- 1, 2 here it's right.. strange.. 回答1: As has already been mentioned,

Swift Cannot invoke 'find' with an argument list of type '([Score], Score)' where Score is a struct

狂风中的少年 提交于 2019-12-21 04:50:42
问题 While find(["a", "b"], "c") works with no problems, I get an error when trying to find the index of a structure inside an array of structures: struct Score { //... } var scores: [Score] = //... var score: Score = //... find(self.scores, score) // Error: Cannot invoke 'find' with an argument list of type '([Score], Score)' I though it could be a problem with structures that can't be compared to each other by default. But changing Score s definition to class gives me the same error. 回答1: EDIT:

Remove domain information from login id in C#

陌路散爱 提交于 2019-12-21 03:20:43
问题 I would like to remove the domain/computer information from a login id in C#. So, I would like to make either "Domain\me" or "Domain\me" just "me". I could always check for the existence of either, and use that as the index to start the substring...but I am looking for something more elegant and compact. Worse case scenario: int startIndex = 0; int indexOfSlashesSingle = ResourceLoginName.IndexOf("\"); int indexOfSlashesDouble = ResourceLoginName.IndexOf("\\"); if (indexOfSlashesSingle != -1)

Remove domain information from login id in C#

帅比萌擦擦* 提交于 2019-12-21 03:20:12
问题 I would like to remove the domain/computer information from a login id in C#. So, I would like to make either "Domain\me" or "Domain\me" just "me". I could always check for the existence of either, and use that as the index to start the substring...but I am looking for something more elegant and compact. Worse case scenario: int startIndex = 0; int indexOfSlashesSingle = ResourceLoginName.IndexOf("\"); int indexOfSlashesDouble = ResourceLoginName.IndexOf("\\"); if (indexOfSlashesSingle != -1)

Find index of value in a sorted vector in R

霸气de小男生 提交于 2019-12-20 01:45:26
问题 I have an ordered vector of unique integers in R and I want to find the index of the element closest to but less than or equal to some value. For example, for the vector 4 8 15 16 23 42 and the search value 17 , I would like the function to return 4 , the index of 16 . In Python, I would use bisect module. Is there anything similar in R? 回答1: You can use binsearch from the gtools package to get the log(n) behavior of a binary search: library(gtools) x <- c(4, 8, 15, 16, 23, 42) binsearch