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

Inserting random letters at random locations within a string

I am trying to make a little script to demonstrate how DNA sequences can evolve using a sentence as an example. I would like to repeatedly replace or insert letters or words into a string in R. I would like this to happen repeatedly so one can watch…
user964689
  • 812
  • 7
  • 20
  • 40
2
votes
2 answers

pattern restriction in substring- Python

I found a question in glassdoor. I do not have additional clarification Input : an int array [1,0,0,1,1,0,0,1,0,1,0,0,0,1] you have to come up with a program that will give all possible subsets of the array based on the pattern. Pattern restrictions…
Sheikh Rahman
  • 895
  • 3
  • 14
  • 29
2
votes
2 answers

Arrays and -contains - test for substrings in the elements of an array

I am trying to filter out users that are in a specific group. I got the following output in a variable: Group1 Group2 etc... One group for each line saved in an array. Im trying to filter out only one specific group. But when I use -contains it…
seyo -IV
  • 173
  • 3
  • 13
2
votes
1 answer

Finding substring in pandas frozenset

I'm trying to find a substring in a frozenset, however I'm a bit out of options. My data structure is a pandas.dataframe (it's from the association_rules from the mlxtend package if you are familiar with that one) and I want to print all the rows…
ch1ll
  • 419
  • 7
  • 20
2
votes
2 answers

Return value between two characters in a string

I'm trying to extract values in a form from a word document so that I can tabulate them. I used the antiword package to convert the .doc into a character string, now I'd like to pull out values based on markers within the document. For…
nbouc
  • 23
  • 2
2
votes
3 answers

Need help for extracting substring from string till last space before certain length

I`m trying to substring up to specific length. For example string length is 100. I need to cut the string at 31 characters but not to cut whole words. PARTNER ESSENTIAL 24 MONTHS INITIAL FOR NETBACKUP SELF SERVICE XPLAT If I simply split aft 31…
SakBG
  • 47
  • 1
  • 5
2
votes
4 answers

Ruby: getting character[n] from each element of an array of strings, strictly with array notation

Suppose I have this: x = %w(greater yellow bandicooot) And I want to get a specific letter of each string as a string. Of course, I can do something like this (to get the first letter): x.map { |w| w[0] }.join # => 'gyb' But I'd like to know…
BobRodes
  • 5,990
  • 2
  • 24
  • 26
2
votes
2 answers

PowerShell cut string in half

I have lines that consist of identical halves from which I want to remove one half; e.g, 'AbcAbc' should become 'Abc'. The data always looks like:…
Paul Dawson
  • 1,332
  • 14
  • 27
2
votes
1 answer

set variable from token in a for loop

I am trying to replicate a shell script within windows bacth. I am getting close but am currently stuck on trying to substring a datetime token to output just the time. @echo off echo."Location","Date Time","Result" > output2.csv ( for %%a in…
user639410
  • 387
  • 1
  • 3
  • 9
2
votes
1 answer

Algorithm: Is it possible to form a valid string

Assume we have n three letter substrings. It is possible to make a string of length n+2 out of these N substrings by concatenating them (Where overlapping letters are written only once) . Whereby this string must have the form a1,a2,a3,a4... So it…
Diefapa
  • 21
  • 2
2
votes
5 answers

How to Use substring in c#?

I have -$2.00 as the string. I am trying to change it to decimal by removing - and $ using substring, but I am doing it wrong. Can someone help me? Thanks.
Remo
  • 389
  • 6
  • 22
2
votes
2 answers

Is there a simple way to invert substrings using regular expressions?

I am manipulating some strings which contain a number and characters. Input strings are such elementX5, elementX50 and so on. I know how to change them elements_10, elements_100 etc. with the following code: import re inp = ["elementX5asdl",…
roschach
  • 8,390
  • 14
  • 74
  • 124
2
votes
1 answer

COBOL substring between two finite points

I understand that the string_variable(start:length) can be used to get a substring of a string given a starting point and substring length, however, I am finding that I often need to get a substring between a 'start' and 'end' point. While I know I…
Matt Haidet
  • 338
  • 3
  • 14
2
votes
2 answers

Trying to get a substring using regex in Python / pandas

I know this may seem stupid but I've been looking everywhere and trying with regex and split in vain. My script never works for all type of string I have on my data set. I have this column that contains raw data that look like (three…
helloworld
  • 416
  • 2
  • 6
  • 15
2
votes
2 answers

How to construct a method chain from an array of method names

Let me show you an example of what I want to accomplish: Say I want to call a functions sub function's sub function's sub function (and so on, lets say for 50+ sub functions), like: foo(arg).bar(other).foobar(int, str).execute(str) and imagine that…
1 2 3
99
100