indexof

How to find index of whole word in string in java

ぃ、小莉子 提交于 2019-11-29 17:42:58
I want to find out all starting indexes of whole word in a given string. Lets say I have a string given below. "an ancient manuscripts, another means to divide sentences into paragraphs was a line break (newline) followed by an initial at the beginning of the next paragraph. An initial is an oversize capital letter, sometimes outdented beyond the margin of text. This style can be seen, for example, in the original Old English manuscript of Beowulf. Outdenting is still used in English typography, though not commonly.[4] Modern English typography usually indicates a new paragraph by indenting

Find word(s) between two values in a string

跟風遠走 提交于 2019-11-29 10:24:41
问题 I have a txt file as a string, and I need to find words between two characters and Ltrim / Rtrim everything else. It may have to be conditional because the two characters may change depending on the string. Example: car= (data between here I want) ; car = (data between here I want) </value> Code: int pos = st.LastIndexOf("car=", StringComparison.OrdinalIgnoreCase); if (pos >= 0) { server = st.Substring(0, pos);.............. } 回答1: This is a simple extension method I use: public static string

MySQL String Last Index Of

允我心安 提交于 2019-11-29 02:58:33
I am able to use LOCATE to get the index of a character such as a . in www.google.com . Thus I can use substring to strip out everything before the first . . Is there a way I can look for the last / ? So I can get test.htm out of http://www.example.com/dev/archive/examples/test.htm ? I do not want to say the 6th slash, I want to say the last slash. Can this be done? Use substring_index select substring_index('http://www.example.com/dev/archive/examples/test.htm','/',-1) 来源: https://stackoverflow.com/questions/5796340/mysql-string-last-index-of

strstr() for a string that is NOT null-terminated

不想你离开。 提交于 2019-11-29 02:56:49
How do I do the in-place equivalent of strstr() for a counted string (i.e. not null-terminated) in C? If you're afraid of O(m*n) behaviour - basically, you needn't, such cases don't occur naturally - here's a KMP implementation I had lying around which I've modified to take the length of the haystack. Also a wrapper. If you want to do repeated searches, write your own and reuse the borders array. No guarantees for bug-freeness, but it seems to still work. int *kmp_borders(char *needle, size_t nlen){ if (!needle) return NULL; int i, j, *borders = malloc((nlen+1)*sizeof(*borders)); if (!borders)

How to use IndexOf() method of List<object>

不想你离开。 提交于 2019-11-29 02:05:25
问题 All the examples I see of using the IndexOf() method in List<T> are of basic string types. What I want to know is how to return the index of a list type that is an object, based on one of the object variables. List<Employee> employeeList = new List<Employee>(); employeeList.Add(new Employee("First","Last",45.00)); I want to find the index where employeeList.LastName == "Something" 回答1: int index = employeeList.FindIndex(employee => employee.LastName.Equals(somename, StringComparison.Ordinal))

Search for all instances of a string inside a string

烈酒焚心 提交于 2019-11-29 01:46:05
Hello I am using indexOf method to search if a string is present inside another string. But I want to get all the locations of where string is? Is there any method to get all the locations where the string exists? <html> <head> <script type="text/javascript"> function clik() { var x='hit'; //document.getElementById('hideme').value =''; document.getElementById('hideme').value += x; alert(document.getElementById('hideme').value); } function getIndex() { var z =document.getElementById('hideme').value; alert(z.indexOf('hit')); } </script> </head> <body> <input type='hidden' id='hideme' value=""/>

MySQL Second (or third) Index Of in String

元气小坏坏 提交于 2019-11-29 01:19:57
What would be the simplest way to locate the index of the third space in a string. My goal is to get CCC out of this space separated list: AAAA BBBB CCCC DDDD EEE . where A and B and D are fixed length, and C is variable length, E F G are optional. In Java I would use indexof, with a starting point of 10 and that would get me the third space, but it seems that I cannot do that in MySQL, so I thought maybe I could find a 'third index of' function? You would want to use SUBSTRING_INDEX function like this SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(field, ' ', 3), ' ', -1) FROM table The inner

Get index of object in a list using Linq [duplicate]

删除回忆录丶 提交于 2019-11-28 20:06:27
This question already has an answer here: How to get index using LINQ? [duplicate] 7 answers I am new to Linq. I have a Customers table.ID,FullName,Organization,Location being the columns. I have a query in Sqlite returning me 2500 records of customers. I have to find the index of the customer where ID=150 for example from this result set. Its a List of Customers. The result set of the query is ordered by organization. I tried with FindIndex and IndexOf but getting errors for the former and -1 for the latter. So, how should it be done? Thanks. You don't need to use LINQ , you can use FindIndex

How to find index of whole word in string in java

我只是一个虾纸丫 提交于 2019-11-28 12:09:18
问题 I want to find out all starting indexes of whole word in a given string. Lets say I have a string given below. "an ancient manuscripts, another means to divide sentences into paragraphs was a line break (newline) followed by an initial at the beginning of the next paragraph. An initial is an oversize capital letter, sometimes outdented beyond the margin of text. This style can be seen, for example, in the original Old English manuscript of Beowulf. Outdenting is still used in English

Getting a collection of index values using a LINQ query

一世执手 提交于 2019-11-28 09:08:56
Is there a better way to do this? string[] s = {"zero", "one", "two", "three", "four", "five"}; var x = s .Select((a,i) => new {Value = a, Index = i}) .Where(b => b.Value.StartsWith("t")) .Select(c => c.Index); i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria. You could easily add your own extension method: public static IEnumerable<int> IndexesWhere<T>(this IEnumerable<T> source, Func<T, bool> predicate) { int index=0; foreach (T element in source) { if (predicate(element)) { yield return index; } index++; } } Then use it with: