Questions tagged [lastindexof]

125 questions
87
votes
7 answers

Last index of a given substring in MySQL

We can find the index of the first occurrence of a given substring in MySQL using the INSTR() function as follows. SELECT instr('Have_a_good_day', '_') AS index_position It would display 5, the first occurrence of the specified substring which is…
Tiny
  • 27,221
  • 105
  • 339
  • 599
42
votes
4 answers

indexOf and lastIndexOf in PHP?

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…
Gaurav
  • 439
  • 1
  • 4
  • 3
19
votes
7 answers

How to check the last char of a string and see its a blank space

How to check the last char of a string and see its a blank space? If its a blank space remove it?
user339160
12
votes
1 answer

How to find the last occurrence of a set of characters from a string

I'm trying to find the last operator (+, -, * or /) in a string. I was trying to use the method string.indexof('operator', i);, but in this case I could only get the single type of operator. Is there any better solution for this? The value of string…
mega6382
  • 9,211
  • 17
  • 48
  • 69
9
votes
7 answers

Find the lastIndexOf() an object with a key in array of objects

I'm looking for a way to find the last index of an object in Javascript from a point in an array. For example: array.lastIndexOf(object.key, start); So far, I haven't found a good solution for this problem. I could splice the array from the…
Xari
  • 266
  • 1
  • 4
  • 13
6
votes
3 answers

lastIndexOf() to find last alphanumeric character

I have a string, and I need to find the last occurrence of any alphanumeric char in this string. Whichever the last alphanumeric character is in the string, I want that index. For text="Hello World!- " the output would be the index of…
Iverie
  • 85
  • 1
  • 5
5
votes
10 answers

How to get characters from second last index using indexof in javaScript?

var absoluteURL = "http://stackoverflow.com/users/6262169/vikas-kohli" var n = absoluteURL.lastIndexOf('/'); var result = absoluteURL.substring(n + 1); //alert(result); console.log(result); Here I get the result like 'vikas-kohli' as I…
VIKAS KOHLI
  • 8,164
  • 4
  • 50
  • 61
5
votes
4 answers

String.Contains and String.LastIndexOf C# return different result?

I have this problem where String.Contains returns true and String.LastIndexOf returns -1. Could someone explain to me what happened? I am using .NET 4.5. static void Main(string[] args) { String wikiPageUrl =…
4
votes
6 answers

Remove the last part of a String in Java

My Code: String Y = "part1 part2 part3", X = "part1"; boolean foundMatch = false; while(!foundMatch) { foundMatch = Y.equals(X); if(foundMatch) { break; } else { Y = useSplitToRemoveLastPart(Y); …
Praneel PIDIKITI
  • 18,677
  • 13
  • 41
  • 60
4
votes
1 answer

How is lastIndexOf() better than indexOf() in this case?

Here's Google's implementation of String.startsWith() taken from Closure Library: goog.string.startsWith = function(str, prefix) { return str.lastIndexOf(prefix, 0) == 0; }; I was wondering why did they choose lastIndexOf over indexOf given the…
resu
  • 944
  • 12
  • 21
4
votes
2 answers

How to get last position of a character in LibreOffice Calc

I want to get last occurrence from multiple occurrences of a character in LibreOffice Calc. For e.g. I have a string abc1ba2ac2adeaa43add. Now if I am searching for a it should return 18.
Ashvin Kanani
  • 831
  • 2
  • 14
  • 22
4
votes
2 answers

lastIndexOf Confusion

I really dont understand how lastIndexOf works. I could not get the usage of second optional parameter. string.lastIndexOf(searchvalue,start) searchvalue -> Required. The string to search for start -> Optional. The position where to start the…
Barış Velioğlu
  • 5,709
  • 15
  • 59
  • 105
3
votes
5 answers

Java - String.lastIndexOf(str) logic I cannot understand

I used two different string to test the last index of "\t", but they both return 4. I thought it should be 5 and 4. I checked the oracle docs and I could not understand why. Could someone please tell me why? Thank…
Carl
  • 107
  • 8
3
votes
2 answers

Substring and IndexOf and LastIndexOf in c#

I have this string : 464-138234-AVENANCE And I need this output on three items : 464 138234 AVENANCE For first item I have try with success : strMyString.SelectedItem.Value.Substring(0, strMyString.SelectedItem.Value.IndexOf('-')) Output :…
Antonio Mailtraq
  • 1,397
  • 5
  • 34
  • 82
3
votes
1 answer

Split String by last occurence

I have a String like this: www.myserver.net/Files/Pictures/2014/MyImage.jpg And I want to split it, so I get the Substring after the last occurence of /. Which means I like to get MyImage.jpg I tried it like this: …
nexno
  • 429
  • 8
  • 26
1
2 3
8 9