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

Marking 1 if word ends with one of the suffixes

Let's say I have this. Words Mark Suffix Happily ly Emotional dom Emotionally Surfdom I want to mark 1 if the word ends with some…
user42459
  • 883
  • 3
  • 12
  • 29
2
votes
2 answers

regex: eliminate all numbers between slashes

Expected: http://some_url.com/api/v1/1/2/3/4" -> http://some_url.com/api/v1/*/*/*/*/ What I use: re.sub(r"/\d+/?", "/*/", str(url), flags=re.IGNORECASE) Actual: http://some_url.com/api/v1/*/2/*/4/
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192
2
votes
1 answer

Get string value after a backslash (\) in JavaScript

I know this question has been asked numerous times on this platform but I am unable to understand how to perform a split on backslash character (\) with the string below. student\boy I tried to split by \ but it gives undefined. function…
nehacharya
  • 925
  • 1
  • 11
  • 31
2
votes
4 answers

Kotlin: strip first and last character

In Kotlin, I need to strip the first and last characters from a string. This seems to be getting compile errors: val MyPiece = str.substring(0, str.length - 1) What's wrong here?
David Pesetsky
  • 254
  • 5
  • 13
2
votes
3 answers

Check if any string in a list is contained within any string in another list

I have a list of news titles and would like to check if any title contains any of the keywords in a list. e.g. newstitle =['Python is awesome', 'apple is tasty', 'Tom cruise has new movie'] tag = ['Python','Orange', 'android'] If any keywords in…
Max Cheung
  • 176
  • 3
  • 13
2
votes
0 answers

Isolating a Substring

I have a bot that stores a file on the cloud, then gives me a link to the file like so: >upload sample.png >>The link to your file is https://filecloud.com/12345/sample.png.html. If this link doesn't work, try…
2
votes
1 answer

R function for removing first 4 characters in a column?

I have a data frame (Data) and I have created a new column with the first four characters of each vector in a column (Details) using substr. Here is the code: Data$Years = substr(Data$Details, 1, 5) How would I use substr (or another function) to…
2
votes
0 answers

Given a list of strings find a new string that is lexicographically smallest and is not a substring of any of the strings in the list

I'm trying to solve this by diving into two parts. First to get the lexicographically smallest values between a list of strings and then to check if it is not a substring in the given strings. For the substring check part, Create a Set from the…
boredDev
  • 317
  • 3
  • 18
2
votes
1 answer

String Recursion Method in Java

I'm trying to write a recursive program: to compute all strings of length n that can be formed from all the characters given in string, but none of the strings listed in sub are allowed to appear as substrings. This is the program I have written…
Roozilla
  • 83
  • 9
2
votes
3 answers

Conditional substring of items in a list (Python)

I have 2 lists. The first is my data list, and the second is a list of randomly generated numbers: alist = ['ABCDEF', 'GHIJKL', 'MNOPQR', 'STUVWX'] blist = [2,0,3,1] I want to substring 3 characters from each item in alist based on the values from…
CAA
  • 79
  • 6
2
votes
3 answers

Managing and substringing multiple strings in a matrix (Python & Numpy)

I have a file titled "test.fa" that reads: >Sequence 1 TCAGAACCAGTTATAAATTTATCATTTCCTTCTCCACTCCT >Sequence 2 CCCACGCAGCCGCCCTCCTCCCCGGTCACTGACTGGTCCTG >Sequence 3 TCGACCCTCTGGAACCTATCAGGGACCACAGTCAGCCAGGCAAG >Sequence…
CAA
  • 79
  • 6
2
votes
2 answers

How to handle unexpected blank space when splitting String by blank space in Java

I am ingesting a file line by line and each line has a varying number of space delimited strings as seen below. This is a single row from the file. The code works as expected except for the case of this line where there is an unexpected space like…
Bryan
  • 149
  • 1
  • 11
2
votes
2 answers

How to remove Duplicate SubStrings

I have a portion of a string which duplicates itself, and I want to remove all duplicate "substrings" without losing the order of the words in the string. For example: "12 PL DE LA HALLE BP 425 BRIVE-LA-GAILLARDE BP 425 BRIVE-LA-GAILLARDE BP 425…
Codious-JR
  • 1,658
  • 3
  • 26
  • 48
2
votes
1 answer

How to assign same id number based on string value R

I have a vector of strings. each one begins with either f1_ or f2_ . > lst_c<-c("f1_cat", "f2_cat", "f1_dog", "f1_camel", "f2_camel") > lst_c [1] "f1_cat" "f2_cat" "f1_dog" "f1_camel" "f2_camel" What I want is to just compare everything…
roger
  • 89
  • 10
2
votes
1 answer

Filtering JMESPath with a string

I can't find the solution despite a lot of research. I'm stuck with the contains function. I have this Json file: { "from": "Api", "success": true, "message": "", "errors": [], "data": { "operations": [ { …
user2030243
  • 49
  • 1
  • 6