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
0 answers

Haskell: How to apply partial order to a substring function?

I have implemented the class POrd and a substring function, which takes 2 strings and determines if the first string is a substring of the second input string. Now I want to apply the POrd class to the substring function to make it so that the…
2
votes
4 answers

Extract substring from index 0 up to searched character

I have an object called user. I can get its name by user.name, and its value has both the first name and last name such as Jon Doe. What is the most efficient and elegant way of grabbing the first character up until the space character so that I get…
EverTheLearner
  • 7,040
  • 16
  • 57
  • 72
2
votes
3 answers

finding substring within a list in Python

I have a list like: a = ['aaa/aa/aa/a001', 'aaa/aa/aa/a002', 'aaa/aa/aa/a003'] I want to retrieve the number part. How can I do that?
이원석
  • 87
  • 2
  • 5
2
votes
2 answers

Get set of numbers from string without regex

"abc_d1.txt" should get 0 "abc_d1_2.txt" should get 2 "abc_d1_14.txt" should get 14 "abc_d12_x2_156.txt" should get 156 Can do this currently with regex int Id; string pattern = @"(?<=_)\d+(?=\.\w+)|(?
user10860402
  • 912
  • 1
  • 10
  • 34
2
votes
2 answers

Excel formula find the shortest string / two digits in a cell

in cell A1, I have strings in this format: xxxxxx xxxxxx xxxxxx 00 xxxxx xxxxxx xxxxx xxxxxx As you can see one (and only one) of these strings is a 2-digit string (e.g. 02). Also this is the shortest string in the cell. Before the 00 part there can…
Kobe2424
  • 147
  • 7
2
votes
3 answers

Swift: String firstIndex after character

I'm trying to detect the parentheses on string for example: foo(bar)baz(blim) to and reverse the content inside of the parentheses but I'm getting out of bounce range on my implementation: func reverseInParentheses(inputString: String) -> String { …
user2924482
  • 8,380
  • 23
  • 89
  • 173
2
votes
2 answers

Node.js get all occurrences of a substring in a string

I have a string in Node.js Runtime e.g var content = "my content contain some URL like https://this.me/36gD6d3 or https://this.me/39Jwjd"; How can I read each https://this.me/36gD6d3 and https://this.me/39Jwjd to replace it with another URL? A…
PasiB
  • 97
  • 9
2
votes
1 answer

Rename column containing substring - Pandas

I need to rename columns in containing specific substring. In my case I am using data with columns that are named a specific date dd/mm/yyyy. I want to rename the column based on the yyyy of the column name (eg. 30/06/2020 rename FY1920). Approach I…
Kasrel
  • 167
  • 2
  • 12
2
votes
2 answers

How to choose the longest ngram in a repetitive string in R?

I have a dataset that looks like the following one (just with more rows): x = c("abov level", "abov level consist", "abov level consist price", "abov level consist price stabil", "abov level consist price stabil protract", "abov level consist…
Rollo99
  • 1,601
  • 7
  • 15
2
votes
1 answer

Replace all occurrences of the substring using slicing when size of replacement string the differs from substring

I want to replace all substring occurrences in a string, but I wish not to use the replace method. It's just study interest. At the moment, experiments have led me to this: def count_substrings_and_replace(string, substring, rpl=None): …
Axel
  • 109
  • 1
  • 1
  • 18
2
votes
1 answer

Sort a vector by a substring

Hi I have a list of files: "1_EX-P1-H2.3000" "10_EX-P1-H2.3002" "100_EX-P1-H2.3074" "1004_EX-P1-H2.4059" "1006_EX-P1-H2.4070" "2_EX-P1-H2.3000" "3_EX-P1-H2.3000" "4_EX-P1-H2.3000" "5_EX-P1-H2.3001" I want to sort not by…
Will
  • 1,619
  • 5
  • 23
2
votes
0 answers

Python task Substrings without loops

You have to count how many substrings of a given string starts and ends with the same letter. You cannot use in your code the following: for,while,sum,map,reduce,filter,import,eval,exec,complile,single My code but doesn't work properly: def…
2
votes
1 answer

XSLT - split string separated with specific character

I have a xml like this, A brief 23 spell$of hea#vy rain$forc^%ed an early+ lunch$98@with nine I need to break the text string from each $ present in the text. SO expected output should be, A brief 23…
2
votes
6 answers

Split string into 3 random-length parts

I have a string and I want to split it into 3 random-length parts (without caring about string length is the objective) to get 3 strings. $mystring = "aHR0cHM6Ly93d3cucGhwLm5ldC9tYW51YWwvZW4vZnVuY3Rpb24uc3RyLXNwbGl0LnBocA=="; When I tried to use…
2
votes
5 answers

How to substring 0 to 30, but only if there is over 30 characters

I have a little problem, I want to substring a String, to max 30 characters, but when I do string.substring(0, 30), it works fine if the string is 30+ characters, but if not, it comes with an error. Does anyone know how to fix that?
Tobias H.
  • 426
  • 1
  • 6
  • 18