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
1 answer

RegexReplace in GoogleSheets To Find Multiple Strings

I have a string such as the following bells<1@gmail.com>,bars<2@gmail.com>, ballots<3@gmail.com> I would like to extract the e-mail addresses out of this string comma separated Formula using is the…
2
votes
2 answers

Remove character based on condition and position in string - R

I am cleaning up a dataset with a character variable like this: df <- c("2015 000808", "2013 000041", "2015 000005", "2015 301585", "2015 311585", "2014 380096", "2013 100041") So I can achieve this result, where the 000s in front of the…
lenlen
  • 79
  • 7
2
votes
3 answers

Count the number of times a substring appears in a file and place it in a new column

Question: I have 2 files, file 1 is a TSV (BED) file that has 23 base-pair sequences in column 7, for example: 1 779692 779715 Sample_3 + 1 ATGGTGCTTTGTTATGGCAGCTC 1 783462 783485 Sample_4 - 1 ATGAATAAGTCAAGTAAATGGAC File 2 is a FASTA file…
KLM117
  • 407
  • 3
  • 13
2
votes
2 answers

Finding subString in String

I'm trying to find the substring in string using O(N) complexity. The following is the code I have written. It returns undefined and I don't know why. Please let me know what is going wrong in my code. let omg = "omg"; let omgi =…
2
votes
3 answers

PowerShell - Removing folder from path of string

Basically I have a path "root/main/EVILFOLDER/first/second/third/etc" And I want to remove EVILFOLDER/ specifically the 3rd segment of the path. The thing is EVILFOLDER could be anything so I can't just hardcode it as such and the path length and…
2
votes
3 answers

Finding part of string and extracting data between delimiter using BigQuery SQL

I have a column like this: String_to_Extract A~S1_B~S2_C~S11 A~S1_B~S3_C~S12 C~S13_A~S11_B~S4 The part before the "~" should be the column name. The part after the "~" should be the row value. This is separated by a "_" .…
Micha Hein
  • 33
  • 4
2
votes
6 answers

Split a string into 2 different substrings vb.net

I'm trying to split a string into 2 subs. The first contains the first 236 (0 to 235) chars and the second one from 237 to the end of the string. firststr = str.Substring(0, 235) secondstr = str.Substring(235, strLength) 'strLength is the total…
l3_08
  • 191
  • 1
  • 4
  • 13
2
votes
1 answer

How to create a function that extracts the last n letters of strings contained in a vector

I'm starting to program in R and I have to create a final function that receives a vector v of character strings and an integer n, and returns another vector of the same length as v that in each position contains a string with only the n last …
Abel Pérez
  • 107
  • 7
2
votes
2 answers

How to find the starting position of the last word from the string in PostgreSQL

What will be the Postgres equivalent for the below code from Oracle. Select instr('abc de fgh',' ', -1) from dual; returns: 7 Original code: substr(country, instr(country,' ', -1)+1); I want to create the same logic in Postgres but position &…
Shalini
  • 33
  • 5
2
votes
3 answers

Changing the column name based on a partial string or substring

I have a data frame df. I can generate this data frame 5 times for 5 different variables. Let's say variables names are: Apple # apple_df Mango # mango_df Banana # banana_df Potato # potato_df Tomato # tomato_df Each time the data frame is…
Sandy
  • 1,100
  • 10
  • 18
2
votes
1 answer

How can I find all common sub strings using Rust , Python, javascript?

Problem Background Git is an awesome version control system, I want learn git by writing my own version control system. The first step I have to do is implement a string diff tool. I've read this blog and this paper. In order to get the diff of two…
2
votes
2 answers

How to I replace the first character of a string only if it's a space in Mariadb (MySQL)

So I have a bunch of contacts in a database whose first names begin with a space. I want to replace the first character of all contacts if it's a space with nothing (I mean ''). For now I have: UPDATE contact SET SUBSTRING(contact.FirstName, 1, 1) =…
user12828557
2
votes
1 answer

How To Find The Repeated occurrence of substring in String Using Java Stream API

public class Test { public static void main(String[] args) { String str = "WELCOMEWELCOME"; // find the occurance of 'CO' in the given string using stream API } }
2
votes
2 answers

Extract text after last occurrence of comma in hive

I want to extract everything after last comma abc,xyz,tuv abc,123,abc,def I want the result as tuv def
user3044949
  • 81
  • 1
  • 4
2
votes
2 answers

How to remove duplicated lines within a list of strings using regex in Python?

I have a DataFrame as below df Index Lines 0 /// User states this is causing a problem and but the problem can only be fixed by the user. /// User states this is causing a problem and but the problem can only be fixed by the user. 1 //- How to…
code_learner
  • 233
  • 1
  • 9