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 extract substring from string

I have a string, that does not always look the same, and from this string I want to extract some information if it exists. The string might look like one of the following: myCommand -s 12 moreParameters myCommand -s12 moreParamaters myCommand -s…
Jill
  • 33
  • 1
  • 3
2
votes
4 answers

Regular expression to extract substrings in python pandas

I have a data frame column name "New" below df = pd.DataFrame({'New' : ['emerald shines bright(happy)(ABCED ID - 1234556)', 'honey in the bread(ABCED ID - 123467890)','http/ABCED/id/234555', 'healing strenght(AxYBD ID -1234556)', 'this is just a…
Kcndze
  • 21
  • 4
2
votes
2 answers

Powershell .contains() check without casesensitive

I'm having a larger foreach loop code but need to get below code executed without casesensitive. Below code snippet returns false, how can I ignore the casesensitive .contains() and the condition as true? $a='aa0855' $b='AA0855…
2
votes
1 answer

PySpark: How do I count number of spaces between in a string?

I know it is doable in Python, but is there any built-in function or Like or IN like facility? For instance, if the name column contains John Doe then it should return 4 as space count. Or should I create a UDF?
Volatil3
  • 14,253
  • 38
  • 134
  • 263
2
votes
6 answers

Why is substring not part of the C standard library?

I know C is purposefully bare-bones, but I'm curious as to why something as commonplace as a substring function is not included in . Is it that there is not one "right enough" way to do it? Too many domain specific requirements? Can anyone…
Derek Springer
  • 2,666
  • 1
  • 14
  • 12
2
votes
1 answer

T-SQL SUBSTRING with CHARINDEX AS LENGTH part is returning too much text

I have ploughed through the massive amount of queries on here relating to SUBSTRING and CHARINDEX but I cannot find one that answers my query. I am extracting a single part of a long piece of text but it is returning 48 characters too much. E.g. in…
2
votes
3 answers

Need help splitting a string into two separate integers for processing

I am working on some data structures in java and I am a little stuck on how to split this string into two integers. Basically the user will enter a string like '1200:10'. I used indexOf to check if there is a : present, but now I need to take the…
3nriched
  • 37
  • 1
  • 5
2
votes
0 answers

Why does my program freeze, after it is finished getting a substring from a large string?

I have a very long string (Copying data to clipboard ~7million characters on average). I want to get the first 50 characters of my string. I am currently doing that with this: rtxtbxClipboard.Text = Clipboard.GetText().Substring(0, 50); …
Fuzz Evans
  • 2,893
  • 11
  • 44
  • 63
2
votes
0 answers

TypeScript string alias repeated substring

I want to create an alias for WKT strings. So I declared a type like below: type WicketCoordinates = `${number} ${number}` | `${number} ${number} ${number}`; Now it is simple to build alias for POINT. But when it comes to other geometries like…
Farhad Rad
  • 563
  • 2
  • 15
2
votes
2 answers

c# substring method error when setting end parameter

I am trying to extract part of a string from itself. I get de string from an http request. I want to slice from position 17, to its Length - 3. Here is my code in c#: var response = await…
WakiApi
  • 25
  • 5
2
votes
1 answer

How can I use multiple substring functions in an update statement?

I have a table with a column called candidate_name in which the names are formatted as lastname, firstname. I'd like to update the column so that the names are in firstname lastname format. I wrote this query to see if the string functions were…
2
votes
3 answers

How do I convert a text file containing a list of lists to a string?

The .txt file has a string like this: [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0]]9.5 My goal is to separate that final number from the list and then turn each of them into a list of lists and a float respectively. I've managed to seperate them but…
jfvcs
  • 21
  • 4
2
votes
1 answer

Generate minimum number of sets of substrings with max substring length

Given a string, I'd like to create the minimum number of sets of substrings where: substrings have a length up to x if two sets differ when a substring in one set can be composed of smaller substrings in the other set, the second set can be…
user697576
  • 780
  • 1
  • 9
  • 11
2
votes
1 answer

Regular Expression to remove " ' from a string in Python

I am fetching my result from a RSS feed using following code: try: desc = item.xpath('description')[0].text if date is not None: desc =date +"\n"+"\n"+desc except: desc = None But sometimes the description contains few unicode html…
Ramets
  • 21
  • 1
  • 2
2
votes
1 answer

Extract the table names from the query string using javascript

I am trying to extract the substring from the query variable For example Var query =“SELECT E.NationalIDNumber, E.JobTitle, P.FirstName, P.LastName FROM Employee E INNER JOIN Person P on E.BusinessEntityID = P.BusinessEntityID”; What…
user u
  • 43
  • 4