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

python pandas substring based on columns values

Given the following df: data = {'Description': ['with lemon', 'lemon', 'and orange', 'orange'], 'Start': ['6', '1', '5', '1'], 'Length': ['5', '5', '6', '6']} df = pd.DataFrame(data) print (df) I would like to substring the…
highbury
  • 107
  • 8
2
votes
1 answer

How can I substring a specific number of bytes from a string in PowerShell?

I have a scenario where I need to obtain an installer embedded within a JSON REST response that is base64-encoded. Since the size of the JSON string is rather large (180 MB), it causes problems when decoding the REST response using standard…
codewario
  • 19,553
  • 20
  • 90
  • 159
2
votes
1 answer

Received MethodError when cleaning String

I have data in a .txt file that looks like this: 04:31 Yuri Kane feat Jeza – Love Comes (Original Mix) [PREMIER] 25:31 Heatbeat & Quilla – Secret (Original Mix) [ARMADA CAPTIVATING] All of them have this pattern: 00:00 artist - title [studio] I…
user19273273
2
votes
1 answer

I have a dataframe with a json substring in 1 of the columns. i want to extract variables and make columns for them

imports json df = pd.read_json("C:/xampp/htdocs/PHP code/APItest.json", orient='records') print(df) I would like to create three columns extra: ['name','logo','ico_score'] instead of the 'main' column I have tried: df2 =…
2
votes
2 answers

Swap two String in java using without using third variable and without any inbuild API in Java

Recently I have given an interview where they have asked me to swap two String without using any third variable and without using any String method like substring, replace or without using StringBuilder and StringBuffer. Eg: String str1 =…
Amit
  • 21
  • 2
2
votes
1 answer

How to obtain the info inside a String without length and indexOF. (JAVA)

I have an api which returns a String in the following format: ACTNEW_38_0001,ACTO_57999 I need to extract the numerical values (57999, or 38_0001) but: 1: They can arrive in different order. 2: It can arrive only one of them. 3: It has to be…
Grismak
  • 192
  • 16
2
votes
2 answers

How is str.find so fast?

I had an earlier problem where I was looking for a substring while iterating the string and using slicing. Turns out that's a really bad idea regarding performance. str.find is much faster. But I don't understand why? import random import…
finefoot
  • 9,914
  • 7
  • 59
  • 102
2
votes
2 answers

Find all substrings

Basically I am trying to get my code to print all substrings of a input. If the input is rum it would go as r u m ru um rum. I am not very good with nested loops and so far the out put I get is rr uu mm. I would appreciate if anyone can help me…
2
votes
1 answer

Xquery to get a string between delimiters

I have (TEI)XML with bits like but also I need to write the xquery code to transform each #-target to a link; this is no problem if I have just one target="#a1", then I use…
Eugenia
  • 21
  • 1
2
votes
2 answers

Convert dict to lists by using substrings

I have the following dict: dict = { "HVAC_flex[1,1]": 8.0, "HVAC_flex[1,2]": 15.0, "HVAC_flex[2,1]": 0.0, "HVAC_flex[2,2]": 0.0, "DHW_flex[1,1]": 0.0, "DHW_flex[1,2]": 2.0, "DHW_flex[2,1]": 4.0, "DHW_flex[2,2]":…
Kosmylo
  • 436
  • 1
  • 6
  • 20
2
votes
1 answer

Change multiple substrings in a text based on other substrings in text with Powershell

We process M940 bankstatements in our ERP-system but the bank does not provide the statement number in the file (it always states 00001/00001) so I want to put the statement-date where the statement number should be. Each statement has a statement…
Kees Netelvrees
  • 119
  • 1
  • 8
2
votes
3 answers

Creating new Pyspark dataframe from substrings of column in existing dataframe

I have a Pyspark dataframe as below and need to create a new dataframe with only one column made up of all the 7 digit numbers in the original dataframe. The values are all strings. Column1 should be ignored. Ignoring non-numbers and single 7 digit…
Dr.Data
  • 167
  • 1
  • 10
2
votes
1 answer

Identify the correct hashtag indexes in tweet messages

I need to identify the correct indexes in twitter messages (various languages, emojis, etc). I can't find a solution that returns these positions as shown in the example below. import ( "regexp" "testing" …
Knüppe
  • 45
  • 3
2
votes
4 answers

Bash split substring

I am receiving numeric variables sometimes with 2, other times with 3 digits, like '321' and '32'. And I want to put a dot among each of the numbers. So if I receive '32', I got to echo '3.2' and if I receive '321' I echo '3.2.1'. This is what I…
Roger
  • 8,286
  • 17
  • 59
  • 77
2
votes
1 answer

Fastest way to check occurrence of a set of substrings in a large collection of documents using R

I have a large collection of documents, dc, (with several million rows) with the following data.frame structure doc_id body 1 'sdfadfs...' 2 'dfadf...' 3 'sadf....' I also have about 10,000 terms (or substrings) stored in…
Ding Li
  • 673
  • 1
  • 7
  • 19