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

awk sub/gsub a substring between 2 matches with end-delimiter repeated

I've a string (file) : 2 61009818 . TAGG T . . ad_alt=9;ad_ref=48;denovo=NA;dp_bin=50; how can i replace the substring ad_ref=48 with example=something, in order to obtain: 2 61009818 . TAGG T . . …
cccnrc
  • 1,195
  • 11
  • 27
2
votes
2 answers

Replacing strings in lua containing special characters

I want to replace string in lua. Here is the string. strng='\begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 10 \end{matrix}' I want to replace \begin{matrix} by {{ & by , \\ by },{ \end{matrix} by }} I also want to remove all spaces. So…
Maths89
  • 476
  • 3
  • 15
2
votes
3 answers

Is it possible to have a set of option for a regex substring in R?

I have a dataframe that contains some cells with error messages as string. The strings come in the following forms: ERROR-100_Data not found for ID "xxx" ERROR-100_Data not found for id "xxx" ERROR-101_Data not found for SUBID "yyy" Data not found…
Aaron Parrilla
  • 522
  • 3
  • 13
2
votes
3 answers

Substring string between underscore - SQL Server 2008

I have a string stored in my SQL Server 2008 and I want to extract the value between the underscores. I have a working code but it creates a problem when the length of the string changes. Could you please let me know a better way to do this? Sample…
2
votes
2 answers

Matching part of a string using a Perl regular expression

In the variable $hobbit I have stored value "Emulex LPe16000". Now I need a regular expression to match the "LPe16000" part of the value after "Emulex". Please ignore any syntax errors,I am a novice at perl..! $hobbit="Emulex LPe16000" if ($hobbit =…
shubham
  • 182
  • 1
  • 1
  • 8
2
votes
4 answers

Find Substring in SQL

I have to find substring as follows. Data as below aaaa.bbb.ccc.dddd.eee.fff.ggg qq.eeddde.rrr.t.hh.jj.jj.hh.hh ee.r.t.y.u.i.ii. I want output as- bbb eeeddde r challenge I am facing is all have (.) as separator so sub-string is tough to…
Andrew
  • 183
  • 2
  • 14
2
votes
0 answers

Why does Javascript have substr() and substring()?

Where did substr() and substring() originate? Why are there two methods to do the same thing with slightly different behaviours? No programmer in their right mind would create two methods with different behaviour where the only difference in the…
Clonkex
  • 3,373
  • 7
  • 38
  • 55
2
votes
2 answers

Is there an equivalent to the "in" keyword in python for C

I'm trying to check if a certain keyword is in the string entered by the user. This is how I would do it in python. keyword = "something" user_input = input("Enter a something: ") if keyword in user_input: # I don't know how to do this part …
2
votes
3 answers

An efficient way to find elements of a list that contain substrings from another list

list1 = ["happy new year", "game over", "a happy story", "hold on"] list2 = ["happy", "new", "hold"] Assume I have two string lists, I want to use a new list to store the matched pairs of those two lists just like below: list3=[["happy new…
2
votes
2 answers

Delphi: strange substring result

Delphi Seattle (S10). Win32 project. Yesterday I got wrong result in my old routine. I found this line: sPre := Copy(aSQLText, p - 1, 1); aSQLText was 'CREATE', and p = 1. The sPre got "C" result. Hmmm... Then I wrote to watch window: Copy('ABC',…
durumdara
  • 3,411
  • 4
  • 43
  • 71
2
votes
2 answers

Java SHA-512 function only producing a 508 bit output?

I have a data points that I loop through and hash. I am using a Java implementation of the SHA-512 to hash my data. The hash should produce a 128 character string, but occasionally it will produce a 127 character string that results in my code…
Riley K
  • 363
  • 3
  • 17
2
votes
3 answers

How to return string within quotes

I'm querying a dataset using Oracle SQL Developer and want to create a column with partial return data from a (CLOB) in another column. The part I need is in quotes and i've used substring to extract however the value will change as will the length…
djd
  • 87
  • 1
  • 9
2
votes
3 answers

will Substring creates another instance C#?

I am new to C# string I am confused about the Object.referenceEquals I was reading some article which says ReferenceEquals check if it same instance or not in the program i am checking if object.ReferenceEquals(s1, s4) even though they point to…
Deepak Jain
  • 109
  • 6
2
votes
2 answers

Parse String data to pick only middle name in full name

I have a column which stores full name. I need to parse this in First name, last name, middle name , prefix etc. Req for middle name is to pick name which is between space and then name with A-z Chars and then space. Foe ex: Name- My name is Middle…
PythonDeveloper
  • 289
  • 1
  • 4
  • 24
2
votes
2 answers

SQL query to select a word from 100 columns

I have 100 columns in an Oracle table like this Sh. North Miladhunmadulu - Shaviyani Atoll . I need a query to select only Shaviyani from the above. Please help me. I need to select data after - and before Atoll word.
user3769901
  • 17
  • 1
  • 3