Questions tagged [lastindexof]

125 questions
0
votes
3 answers

How do I find the index in a string of where my nth occurrence of a regex ends?

Using Rails 5.0.1 with Ruby 2.4. How do I find the index in a string of where the nth occurrence of a regex ends? If my regex were /\-/ and my string where str = "a -b -c" and I were looking for the last index of the second occurrence of my…
Dave
  • 15,639
  • 133
  • 442
  • 830
0
votes
3 answers

Substring IP-Address with adding a string generates error but works

I have following command: $IP_start = $First.Substring(0, $First.LastIndexOf('.'))+ ".200" $First is an IP-Address, for example 192.168.0.1 I want to change the 1 in the fourth octect into a 200. Write-Output $IP_start gives me the correct…
0
votes
1 answer

How to find index of whole word in string in java

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 …
Ravi Godara
  • 497
  • 6
  • 20
0
votes
3 answers

getLastIndexOf(int item) LinkedList

I'm currently a freshman comp sci student working on learning data structures both through my class and also online. I'm new to stack too but it has helped me a lot in the past. My current problem is searching through a LinkedList to return the last…
Pansock
  • 3
  • 1
0
votes
0 answers

Using regexp to filter an array

I'm trying to use a RegExp in a .filter() method, the problem is that I am using /g on the regexp, so after the first iteration, the .lasindex is not longer 0 and I am getting false as result. Is there any way to reset the .lastindex during next…
0
votes
2 answers

Extract correct combination of digits from string

I am working on a method which extracts the correct version number from a String (for later comparisation if there is a new version). The String which is being provided unfortunatly has no fixed pattern and can have multiple combinations of…
Simon
  • 1,691
  • 2
  • 13
  • 28
0
votes
2 answers

return substring within an array

I found a good solution but not exactly for my problem: String s = "abc.def.ghfj.qert"; s.substring(s.lastIndexOf(".") + 1) Source: Java: Getting a substring from a string starting after a particular character This I have to use it within an…
0
votes
1 answer

Swapping and Changing scripts

Hello my task is to swap the first and last words and capitalize the first letter of the first word Say i input one two three four My output turns out to be fourTwo three fourone Here is my code I am a beginner so please be easy import…
Beginner
  • 1
  • 1
0
votes
1 answer

Qt QString lastIndexOf not working

I'm using Qt5.6, I'm trying to use the QString function lastIndexOf. The subject data contains something like: 156 + (28 * 4) + (14 * 9 * 2) Using indexOf: int intOpB = strLocalCopy.indexOf(ucOpenBracket); strLocalCopy contains the…
SPlatten
  • 5,334
  • 11
  • 57
  • 128
0
votes
3 answers

Substr starting at one character OR one other character

I have a function that takes an argument and needs to return that argument as a substring of it's original string: var $ = function (selector) { var elements = []; var selectorSubstr = selector.substr(selector.lastIndexOf(".") ||…
Joe
  • 678
  • 9
  • 24
0
votes
0 answers

Why does MEAN js unique error handler search for '.$'

MEAN js has an error handler for mongo unique error. Here's the code: var getUniqueErrorMessage = function(err) { var output; try { var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1')); …
Dushyant Bangal
  • 6,048
  • 8
  • 48
  • 80
0
votes
3 answers

c# lastindexof throwing an exception

I am unsure why this is throwing an exception. This code is supposed to take the cursor position then get the last index of space or enter to pick out a the last single word typed.It sometimes throws an exception of out of range. Is the selection…
Peter S McIntyre
  • 409
  • 4
  • 12
0
votes
1 answer

vb.net string.split vs substring.lastindexof - which is faster or 'better'

I have a loop that reads through a lot of strings, each string containing information split by a char (¥). For this loop, i only really need the end value, which i know the index of. I am wondering if it is better to use string.split, or to use…
user2366092
  • 53
  • 1
  • 9
0
votes
0 answers

c# break string into arrays to print on different lines with zebra printer

I am using a zebra card printer. I'm working with a group to design a program that will allow a user to input their desired information into different boxes and print out accordingly, however there's a place in the form that allows administrative…
user5360843
0
votes
0 answers

Doubly LinkedLists type Generic, can't get lastIndexOf() method to work

Ran into a slight problem of where for my DoublyLinkedList's lastIndexOf(E element) only returns -1. My code for indexOf(E element) works correctly though. I'm using my DoublyLinkedListIterator to do the finding. The code for that is currently:…
1 2 3
8 9