Questions tagged [lastindexof]
125 questions
1
vote
0 answers
How to return undefined instead of -1, findLastIndex()
In this challenge, I need to return the index position of the last element that is true for a callback. I know findLastIndex returns the last index position, however I need to return 'undefined' instead of -1 if the callback doesn't result in true.…

Joe M
- 21
- 3
1
vote
1 answer
z3 LastIndexOf returns wrong result?
z3py's LastIndexOf is supposed to return the "last index of substring within a string". However, it seems to return the wrong results when the substring is located at the end of the string, for example:
>>> import z3
>>> def check_lastindexof(s,…

hemx
- 13
- 2
1
vote
2 answers
Trying to find the index of the last uppercase char using regex
I need a little bit of help trying to find the last index of the last uppercase char in the string. I have been using regex to do so. However it keeps returning -1 instead of the index of B which is 7.
The code is highlighted below
public class Main…

DAVE
- 61
- 4
1
vote
2 answers
Get multiple substring between two characters javascript
I'm taking this post as reference where they suggest this solution:
Current
Str = 'MyLongString:StringIWant;'
Desired Output
newStr = 'StringIWant'
Solution
var mySubString = str.substring(
str.lastIndexOf(":") + 1,
…

Christopher Martinez
- 779
- 2
- 8
- 24
1
vote
1 answer
Is C# string.LastIndexOf always culture specific?
x is a string in any language/culture and want to find the last dot in the string:
int y = x.LastIndexOf(".");
Is the result (y) culture independent or not?
Why?

rodins
- 306
- 2
- 11
1
vote
3 answers
Getting last index of arraylist with condition
I have list as shown below, as this includes many repeated field values of AbcConSch
List asBeanList= tbCondition.getAbcConScheds();
AbcConSch abcSchedule = asBeanList.get(i);
this list has bag which has elements of data, so i need to…

Arun Kumar A
- 93
- 1
- 1
- 6
1
vote
2 answers
Java - Get substring from 2nd last occurrence of a character in string
My input: "professions/medical/doctor/"
My desired output: "doctor"
I have the following solution but it is not a one-liner:
String v = "professions/medical/doctor/";
String v1 = v.substring(0, v.length() - 1);
String v2 =…

activelearner
- 7,055
- 20
- 53
- 94
1
vote
1 answer
How do I write a live search function for my dynamically generated table?
I have a script that generates a dynamic table from values stored in an array. I would like to write a live search function searchByNumber(). How do I write a live search function based on values in the Amount and Time column that would dynamically…

SirBT
- 1,580
- 5
- 22
- 51
1
vote
5 answers
Remove rest of string after the second to last index of
I'm relatively new to JS and pretty confused. I have a URL string: https://a/b/c/d/e/f. These are all dynamic characters and change often (could be https://x/s/g/e/h/d for example) In some cases I want to remove only f, in which I use LastIndexOf.…

Uciebila
- 481
- 2
- 9
- 27
1
vote
5 answers
Defining a function lastIndexOf?
I am working on a textbook.
This is the question:
Define a function lastIndexOf, which, given an array and a value, returns the index of the last time the value occurs in the array. If the value never occurs, the function should return -1.
Then…

billygreen
- 223
- 3
- 12
1
vote
4 answers
How to find the last word inside a string which is seperated by " "? C#
Thank you all for the help I have got it working with your help.
So I have written some code which extracts the first word within a string. Below is my code.
var LongString = "Hello World";
var firstWord = LongString.Substring(0,…

user9710070
- 65
- 1
- 8
1
vote
4 answers
Java- How to find non-alphabetical letters in a string? (Quick way)
In Java, given a string, like "abc@df" where the character '@' could be ANY other non-letter, like '%', '^', '&', etc. What would be the most efficient way to find that index? I know that a for loop would be kind of quick (depending on the string…

Jsbbvk
- 180
- 2
- 19
1
vote
2 answers
Java lastIndexOf always return -1 if the character is space and fromIndex is set
Test Code
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World".lastIndexOf(' '));
System.out.println("Hello World".lastIndexOf(' ', 1));
System.out.println("Hello…

Joshua
- 5,901
- 2
- 32
- 52
1
vote
3 answers
Why is C#'s LastIndexOf behave this way?
I have the following code:
string s = "Hello, World!";
Console.WriteLine(s.LastIndexOf("World"));//7
Console.WriteLine(s.LastIndexOf("World", 7));//-1
Why the result of the second call to LastIndexOf is -1 and not 7?

User0123456789
- 295
- 3
- 8
1
vote
0 answers
Java URLResource, LastIndexOf,IndexOf,substring method code explanation?
Can someone please help me understand this bit of code with an example. I have been struggling just to get my head around this code.
URLResource file = new URLResource("http://www.dukelearntoprogram.com/course2/data/manylinks.html");
for…

rrene
- 313
- 1
- 3
- 14