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 replace and insert a new substring in python?

This is a working code and mabybe not very effcient code to replace a substring with another substring previously modified Input string : text = ["part1 Pirates (2006)", "part2 Pirates (2006)" ] Output string: Pirates PT1 (2006) Pirates…
user14857172
2
votes
1 answer

how to perform a pandas dataframe subsetting using index and assign it a same value?

How to partially split a dataset from row indexes, and column names or column indexes. I tried this df.loc[[1,2,34,'name']] = 100 and df.iloc[np.where(df.loc[,'name']<100)]=100 this do not work. Need help, thank you! data sample: >> df >> name …
Marc
  • 320
  • 2
  • 9
2
votes
1 answer

Filter in jq based on an array of string

This is close to this question: jq filter JSON array based on value in list , the only difference being the condition. I don't want equality as a condition, but a "contains", but I am struggling to do it correctly. The problem: If want to filter…
tomsoft
  • 4,448
  • 5
  • 28
  • 35
2
votes
2 answers

Find String Function in [ C ]

Needing a function that would check me for the existence of a substring and give me the location I created this function, I wanted to know if something similar already exists in the C headers and how it works. This own function give the position…
ExagonX
  • 141
  • 10
2
votes
3 answers

Extract the first number (with decimals) after a given symbol from a string with multiple numbers in R

I'm trying to get the numbers (including decimals) from a string. My data is similar to this: V <- c("7.20-<7.35","25-<32","60-<83e","40-<50","0.85-<1.15","80-<98","3.0-<3.4","NA","3.0-<3.4 (110)") Where numbers are mixed with letters and…
ACLAN
  • 401
  • 3
  • 9
2
votes
2 answers

Deleting characters after a certain character in SAS

I have the following dataset DATA EXAMPLE1; INPUT Names $char30.; DATALINES; AARON RAY, MD INC AARON,RAY MD (1371927) RAY,AARON,MD ; run; I want to delete all characters after 'MD'. Expecting below output Names …
PriyamK
  • 141
  • 10
2
votes
3 answers

How to generate a list of strings in which another string appears

I need to check if a string exists or not within a larger set of strings and if it does exist to add the string which contains it to another list. I have code that checks the presence ok and it works but it cannot add the string because of my…
Windy71
  • 851
  • 1
  • 9
  • 30
2
votes
3 answers

String slicing in python

I want to slice word from the end.Suppose, I have some line with case sensitives(Upper/lower case) Abc Defg Hijk Lmn Xyz Lmn jkf gkjhg I want to slice them as like below : Abc Defg Hijk Abc Defg Abc Then I need to take each sliced line in…
Big.Bang
  • 33
  • 5
2
votes
2 answers

Remove text before an array of subtexts

I have a set of strings I need to manipulate. Of each, in case they include a set of substrings, I want to keep the substring, otherwise leave it untouched. Here follows an example: keep <- c("USA","UNITED STATES") keep <- paste0(paste0("…
MCS
  • 1,071
  • 9
  • 23
2
votes
3 answers

Max of substring in column

Given that I have a column of values in the format 01.2020 12.2021 3.2019 02.2020 etc. over a million rows or so, I want a VBA function to find the maximum value of the digits to the left of the period. Something like Option Explicit Sub test() …
eirikdaude
  • 3,106
  • 6
  • 25
  • 50
2
votes
1 answer

R: merge two dataframes based on substring

I have two dataframes. The df1 one looks like: Day Element Incident 1 2020-04-06 3101 Check incident by SOILING 2 2020-04-02 3102 Check alarm 5662 3 2020-05-21 3101 Check energy loss by METEO…
MustardRecord
  • 305
  • 4
  • 14
2
votes
1 answer

How to choose a regex pattern in Python

I'm studying Python 3 but I'm struggling to get regex with the re module. Here's my problem: I have the string phrase = "s000000000 s1133122 s21 s3 s4 s5212638476234857634 s6 s7 s8 s9000" and, using the function re.findall(pattern, phrase) I'd like…
jnsen76
  • 23
  • 3
2
votes
1 answer

Subscript 'subscript(_:)' requires that 'String.Index' conform to 'RangeExpression' happened only when i use static value from Struct

I have ridiculous error using strings var myString = "A" print(myString[myString.startIndex] == "-") // false this code works really fine, but when i replace "-" with same character in struct like this: var myString = "A" struct number { …
Dan Choi
  • 83
  • 2
  • 8
2
votes
2 answers

replace the nth character of a string (RegEx or not)

I'm trying to program a vocabulary game. Let me say at the outset that I'm a completely rookie programmer! I am using a regular expression to hide a word, which I have to guess. Take for example the chosen_word: 'TO CRANK (STH) UP' With RegExs I…
2
votes
10 answers

Love letter String rotation company test programming question base testcase passed, hidden testcase failing

I Gave a test on platform named mettl for hiring of a company. Problem statement : You write a love letter to you friend. However, before your friend can read it, someone else read it and rotates the characters of each word to the right K times.…
ASharma7
  • 726
  • 3
  • 8
  • 27