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

Match until the first occurence of the last character of a string

I've tried googling this but all I can find is how to match until a known character occurs. In my case I don't know the character beforehand. I know I can match the last character of a string with (.?)$, and I know that I can match until a character…
sollniss
  • 1,895
  • 2
  • 19
  • 36
2
votes
1 answer

printf doesn't always print correctly

I know this question was asked here several times. I followed methods mentioned like initialize variable start (int start = 0), or typecast it to int in printf statement. But these methods do not help. So I open up this post to ask this question…
George W.
  • 39
  • 4
2
votes
2 answers

Check substring in dataframe column by referencing string position

I have a dataframe with a column called 'id', where each id is 9 characters long, and I'm trying to add a column 'Rating' where I rate each row as A, AA, or AAA based on whether the 6th, 7th and 8th characters are 'A00', 'AA0' or '000'. I've got the…
user356
  • 303
  • 2
  • 10
2
votes
2 answers

Using CMD on Windows to remove a specific substring from a directory of files

I frequently use a free online lossless file compressor to save space on my disk and make transferring and pushing repos easier. My main problem with the compressor is it appends "-min" to the end of every filename. For various reasons, I want to…
2
votes
2 answers

Kotlin: is there a class for substrings?

There is a recursive function that takes a string as input. It breaks this string into parts and calls itself for each part. This function does not change the input string, only reads it. The function is implemented in Kotlin. To create a substring,…
Andrey Epifantsev
  • 976
  • 1
  • 11
  • 27
2
votes
1 answer

Delete substrings in pandas DataFrame with python

I want my python script to delete a row in a DataFrame, if the term at the current index is a substring of the following term. And also, if the following term is a substring of the term at the current index. In the following example only the last…
Finito
  • 35
  • 5
2
votes
3 answers

function replace substring returns incorrect answer

I have a program replacing a substring in a string. The idea is to find the string_to_be_replaced in original_string, then realloc the new_string and connect it to replace_by string. It works for some cases but in some cases like below, it return…
Becker
  • 147
  • 7
2
votes
2 answers

Grabbing only text/substring between 4th and 7th underscores in all lines of a file

I have a list.txt which contains the following…
2
votes
2 answers

Get value of attribute from a string

I have string and I want to get value of an attribute from this. This is how string look like. Lorem Ipsum is simply dummy text of the printing and typesetting industry.[fusion_faq filters="no" featured_image="no" cats_slug="unibet-india"…
wpdd
  • 416
  • 3
  • 15
2
votes
3 answers

SAS extract substring from string with prxchange or prxpson(prxmatch(prxparse()))

2 SOLUTIONS POSTED AT BOTTOM My code data test; extract_string = ""; my_result1 = prxchange(cat("s/^.*", extract_string, ".*$/$1/"), -1, "A1M_PRE"); my_result2 = prxchange(cat("s/^.*",…
Jayden.Cameron
  • 499
  • 4
  • 17
2
votes
1 answer

How to remove enum from string?

I have a set of enum values and an input string, and in case the string has a suffix which is one of the enum names, I want to delete it. For example, let's say I have enum colors { red, blue, green, white } And I receive the input string "str =…
MaayanA
  • 27
  • 2
2
votes
5 answers

String return value in recursive function in java

So I'm practicing java currently, I'm a beginner and I try to explain all the examples that I code so I can understand how and why things are like that. I understand the concept of recursion but I came across this problem when I tried to explain…
2
votes
1 answer

Regex to extract sub string from complex string

I've a string that can have in two formats, First Format: route-policy testPolicy if (destination in pfx_manju) then set extcommunity rt (10429:103) additive endif end-policy Second Format: route-policy testPolicy if (destination in EXP1)…
Prasad
  • 1,164
  • 1
  • 10
  • 27
2
votes
2 answers

Clever use of SUBSTRING on Codewars, can someone plesae explain to me how this works? - Postgres

Please assist me in explaining how the coder created this great solution, I'll briefly explain the table: select * from people returns the value: name Anibal Dorothea Tromp IV The challenge is solved in many ways, but one solution really amazed…
Timmay
  • 37
  • 6
2
votes
2 answers

How to find the positions of all instances of a string in a specific line of a txt file?

Say that I have a .txt file with lines of multiple dates/times: 5/5/2020 5:45:45 AM 5/10/2020 12:30:03 PM And I want to find the position of all slashes in one line, then move on to the next. So for the first line I would want it to return the…
justmayo
  • 41
  • 1
  • 6