Questions tagged [substring]

Part of a string, or the function/method that returns part of a string

substring functions/methods come in basically two flavours:

  • The parameters to the function are start index and length.
    • SQL's version uses this flavour, notably using one-based indexing
  • The parameters to the function are start index and end index. C like languages (including Java) use this flavour, and all use zero-based indexing

Definition

  • A substring is a string contained in a given string.

  • The substring can start at any index of the given string and finish in any index within the given string following the start.

  • It can be an empty string, the entire given string, or (most likely) a shorter string completely encompassed by the given string.

See Also

9558 questions
2
votes
2 answers

How can I pad a string with a variable number of leading zeros?

We have this formula in our MS Flow - Update Item task... concat(items('Apply_to_each')['T_x002d_Code'] ,'-' ,items('Apply_to_each')['BoxNo'] ,'-' , items('Apply_to_each')['ID']) but we need to add leading zeros to the BoxNo and ID so it ends up…
Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148
2
votes
1 answer

Why does substring extraction extract entire words instead of characters?

Given a file test.txt, with the content This is a test. I want to extract a substring of its content, more specifically the second and third character ( hi ), using the command echo ${$(cat test.txt):1:2} However, this outputs the second and third…
flackbash
  • 488
  • 2
  • 16
2
votes
2 answers

How to use gsub to remove . at the end of the string in ruby?

I need to remove all the special characters from the end of the string that sometimes will be there and sometimes not. I have written this .gsub(/[,()'"]./,'') but it does not remove the . (full stop) from the string. Can you tell me what is wrong…
vikas95prasad
  • 1,234
  • 1
  • 12
  • 37
2
votes
2 answers

How can i check if a string has all characters of a substring?

I need to find if a string has all characters of a substring. So for a 7 char string i want to know if the chars of a 5 char substings are in the string, without repeating letters (if substring has 2 letters a, then the string needs at max 2 letters…
Gundro
  • 139
  • 9
2
votes
4 answers

Extract Portion of the URL after "Home"

I need to extract the rest of the portion of the URL after "home" for example the URLs can…
2
votes
1 answer

Code works in console but not in Hackerank

My code works in console but gives the wrong result in hackerank Problem: Print count of all substrings that are palindromes from a string function isPalindrome(str) { var len = str.length; var mid = Math.floor(len / 2); for (var i =…
GeekInTraining
  • 135
  • 1
  • 1
  • 5
2
votes
5 answers

Get specific words from a string in Java

If I have the following URL: http://www.example.com/wordpress/plugins/wordpressplugin/123/ver=1.0 How can I get the name of the plugin (simply named wordpressplugin in the URL) and the version so the output will be - wordpressplugin ver 1.0?
Daniel
  • 21
  • 3
2
votes
3 answers

PHP insert
whenever substring is longer than x characters

I am trying to create some PHP code that will check the length of individual substrings within a string and insert "
" whenever a substring is longer than x characters. The string is always of the following form: aaa bbbbwer sdfr
ert tyuo…
RLJ
  • 135
  • 2
  • 6
  • 10
2
votes
1 answer

Substring after last dot

In my MySQL I have a table user. There's an email field. Some emails have many dots in them, e.g.: firstname.lastname.smth.else@example.com I'd like to select everything after last dot. In case of the email above it'll be com. So far I've came up…
htshame
  • 6,599
  • 5
  • 36
  • 56
2
votes
5 answers

How could I cut off text after a keyword?

So say I would write something like and it would show everything before out of $text = "I like apple piesDo you like Apple pies?"; So it should only output I like apple pies
Keverw
  • 3,736
  • 7
  • 31
  • 54
2
votes
2 answers

lua string.find not recognising substring

I am using LUA as part of a minecraft mod - I am not sure how much that affects things - see openComputers. The code attempts to match a given string to one obtained by iterating over a series of slots containing items which have names. The chunks…
ratchet600
  • 69
  • 4
2
votes
5 answers

Extracting substrings from a string in Java

I have a number of files and they are all called something like name_version_xyz.ext. In my Java code I need to extract the name and the version part of the filename. I can accomplish this using lastIndexOf where I look for underscore, but I don't…
Mejram
  • 21
  • 2
2
votes
3 answers

Java replace a character in a string between two characters using the indexes from the substring function

I have a date in string like this: 10-10-2018, Which I want to be displayed like 10-Oct-2018, I am doing the following: String date = "10-10-2018"; String newDate =…
user9780359
2
votes
1 answer

Capture substring within delimiters and excluding characters using regex

How could a regex pattern look like to capture a substring between 2 delimiters, but excluding some characters (if any) after first delimiter and before last delimiter (if any)? The input string looks for instance like this: var input = @"Not…
RickyTad
  • 281
  • 1
  • 3
  • 15
2
votes
1 answer

Find html tag using substring with beautifulsoup in python3

With the following code: url ='http://lampspw.wallonie.be/dgo4/site_ipic/index.php/fiche/index?sortCol=2&sortDir=asc&start=0&nbElemPage=10&filtre=&codeInt=62121-INV-0018-02' soup = BeautifulSoup(page.content, 'html.parser') t = soup.find_all("div",…
francois
  • 43
  • 4
1 2 3
99
100