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

C# - Finding a string between two strings

I have a string that looks like this: Value->Value2->Value3->ImportantValue->val. I would like to extract ImportantValue. I have read other posts concerning this question but none of them works for me. I tried this: int pFrom = path.IndexOf("->") +…
Mysterio
  • 139
  • 12
2
votes
5 answers

Javascript RegEx Find Variable String Without Substring?

var str = "Visit tEsT!"; var ara = "test"; let n = str.search(/\b + ara + \b/i); // Sadly code doesn't run document.getElementById("demo").innerHTML = n; I want find ara variable in str variable with regex search().
2
votes
2 answers

Remove substring at the end of a string based on a list of strings to remove

I have a list of strings x=['llc', 'corp', 'sa'] I need to filter at the end of a column in my dataframe containing strings: df = pd.DataFrame(['Geeks corp', 'toto', 'tete coope', 'tete sa', 'tata corp', 'titi', 'tmtm'] , columns =['Names']) as…
2
votes
1 answer

Casting expression's result in criteria api

I have this code: CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Integer.class); Root c = criteriaQuery.from(Teacher.class); Expression s =…
Vytsalo
  • 670
  • 3
  • 9
  • 19
2
votes
0 answers

Extracting a substring based on a different table and fill other column with it in SQL

I came upon a problem with source data that I need to solve. I have a table with All Employees column that has several names that I would like to extract and fill other columns with. Please see example below where I have the All Employees from raw…
2
votes
1 answer

How do I remove a substring/character from a string in Scala?

I am writing a program in which I need to filter a string. So I have a map of characters, and I want the string to filter out all characters that are not in the map. Is there a way for me to do this? Let's say we have the string and map: str =…
LondonMassive
  • 367
  • 2
  • 5
  • 20
2
votes
2 answers

How to create field from substring of another field in MongoDb?

I need to create a new field from a substring (two characters string) of another field in MongoDB. Help me, please. Example: field1 field2 abcdef ab qwerty qw opuytj op My code: db.mycollection.update({}, {$set : {"field2": { $substr: […
2
votes
2 answers

Batch: Replacing just the first character in a string if it is a certain character

I have several datalines like so: v1.4.00.29 - SP.CNG v1.0.2.2 Update Kit - Secure USB Token v1.1.1.1 …
SRel
  • 383
  • 1
  • 11
2
votes
2 answers

How to quickly search for a substring and surrounding characters in a large string?

I have a file from which I need to find 10 characters before and after every substring instance. For example, from: (1M characters)...ldkS9jfasdfalkasjFalskdfjsDljBASHcslakfjsalZkf4djfsa3Jkjl...(1M characters) I would like the…
2
votes
2 answers

Program to print all substrings of a given string

I am having trouble creating an algorithm that prints all substrings of a given string. This is my implementation now: #include #include // Function to print all sub strings void subString(char str[], int n) { // Pick…
2
votes
3 answers

Get string from list if that string contains substring

Lets say I have following data: l = ['abc', 'def', 'ghi'] sub = 'bc' 'bc' will allways be a substring for only one element in the list! and a function that works like this: def f(l, sub): return [x for x in l if sub in x][0] So the function…
2
votes
2 answers

Extract substring from text

I'm writing a parser, where it reads all lines in a particular file and processes it!! I got stuck with this substring Abc [123] where ABC should be stored at as one string, and 123 as other string.so i came up with this solution…
Sai
  • 225
  • 3
  • 15
2
votes
1 answer

How can I remove chars from index 0 to index of charAt

I have this basic java question that I would like to get an answer: I need to remove all characters in a String from the beginning to an index determined by a char. String str = "And the priest said: Come to me, you sinners". I want to remove the…
Lyra
  • 61
  • 1
  • 11
2
votes
2 answers

Is there a way to abbreviate each element of an object in R?

I want to abbreviate each word in an object that is longer than 5 characters and replace the removed characters with a "." i.e. x <- "this example sentence I have given here" would become "this examp. sente. i have given here" I imagine this would…
EcoEvoJen
  • 37
  • 2
2
votes
1 answer

Checking if dataframe groups contain substring from provided list (case insensitive)

How do I print/return the value based on values from another column? df = my_df[['Index', 'FRUITS']] print(df) Index FRUITS 7 Green Apple 7 Mango 7 Orange 7 Strawberry 9 …
Yash Ghorpade
  • 607
  • 1
  • 7
  • 16