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

How to return full substring from partial substring match in python as a list?

I have different length strings which have to be checked for substrings which match patterns of "tion", "ex", "ph", "ost", "ast", "ist" ignoring the case and the position i.e. prefix/suffix/middle of word. The matching words have to be returned in a…
tnsoom
  • 45
  • 3
2
votes
0 answers

Finding strings that do not include specific patterns in Lua

(Sorry if the title is vague, I couldn't figure out a way to summarize this properly even though the problem itself is easy). Say I have a Lua string like this: s = "dog frog bag bog cat shop hog" and I want to get a substring from it that only…
2
votes
1 answer

Searching an array for a substring in Javascript

I have searched across the web though have not had any luck in correcting my issue. What I want to do is search an array for a substring and return the result. An example of the array is like this: the_array = ["PP: com.package.id, NN: Package…
ctrled
  • 23
  • 2
2
votes
4 answers

How to substring column in R using different character locations for each row

I want to create an additional column in a dataframe, which is a substring from an existing column in the dataframe, but using different start and end points for each row. Specifically, the column "codes" in the example below contains a single colon…
lf208
  • 77
  • 5
2
votes
5 answers

How to swap character positions in a string JavaScript

I'm making a deciphering function and I'm stuck on a part where I need to swap the positions of the second letter and the last letter of the string. I have also tried using the replace method but I think substring should be used. Hello should equal…
tarik
  • 33
  • 7
2
votes
2 answers

Find total number of substrings with 1's greater than 0's, need optimization

Given and string we need to find out the total number of substrings in which 1's are greater than 0's. I approached this problem using Dynamic programming but I was not able to come up with a solution, I am successful in writing a naive-logic but I…
OpOp_1
  • 59
  • 8
2
votes
3 answers

How to slice off a string in Ruby using another string?

Say I have a sentence similar to the following: The quick brown fox jumps over the lazy dog I'd like to slice off everything before and including "jumps", so I am left with: over the lazy dog Currently, I get the index of the part I'd like to…
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
2
votes
2 answers

Memory access violation in C : Trying to write substrings from char** to char**

I have some strings stored inside a 2D character array like that: char** strings = malloc(4*sizeof(char*)); strings[0] = "this:is,an,example\n"; strings[1] = "another:example\n"; strings[2] = "hello:dear,world\n"; strings[3] =…
2
votes
3 answers

Removing characters after a substring in a field in SQL

I apologize if this has already been done but I'm having trouble finding an answer. I'm trying to clean up some data after rebuilding a database. The database is for an art store. The old way of doing it is we'd have a Product table and the Product…
Bill
  • 95
  • 2
  • 10
2
votes
1 answer

Swift Get substring after last occurrence of character in string

I am creating a post upload page that needs to detect when the user types the "@" symbol so it can search the database for the username. My code works for the first "@" in the string but does not work for any additional ones. I want the user to be…
2
votes
2 answers

Find all possible string of length k with recursion

For string s = "abcd" ,k=3 then answer should be: abc abd acd bcd code by java with recursion(k=3) : public class SubString { static ArrayList al = new ArrayList<>(); public static void main(String[] args) { String s =…
dd000
  • 21
  • 2
2
votes
2 answers

Match Substring from Command Output

There are some close candidates for this question having already been answered, and I've tried several methods of trying to solve the issue. Specifically, my scenario is this: I have an array of utility names that may or may NOT be installed on a…
frazzled
  • 21
  • 1
2
votes
5 answers

How can I access the certain indexes of string using the function?

I was practicing and found some exercise on the internet and it says that I should copy str2 to str1, perhaps the main problem is that I should copy only a certain index of that string (so from str2[a] to str2[b]). Therefore A and B should be…
2
votes
1 answer

PHP string intersections, greedily strip left from right

I'm looking to strip a string, $left from the left of another string, $right. Given: $left = 'alpha beta gamma'; $right = 'beta gamma delta'; The desired output would be: string(6) " delta" Now, I've sort of accomplished this. I've written a…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
2
votes
1 answer

RECURSION in PYTHON to make all possible PERMUTATIONS without repeat

I have written a code using recursion, which follows the following rules: RULES 2 inputs: 1st input: define the length of the output, as an integer. 2nd input: write all elements that user want, as a string, that will be part of the output. With…