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

Remove the input string from the original myString

I am trying to remove the input string from the public string myString myString = "Hello" removeS("el") will return "Hlo" Heres my code below and the problem in it is incompatible types: java.lang.String cannot be converted to int in my String…
2
votes
4 answers

sub string according to some sign

Q: I want to get sub strings according to some sign like - . EX: if i have string like this : saturday-sa-0- and i wanna to get: saturday sa 0 I search and find the following method: string substring = name.Split('-')[i]; my code block…
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
2
votes
2 answers

Unexpected behavior with grep for replacing substrings

I'm having some troubles understanding how to use grep to achieve an apparently simple task. I wanna match a substring that appears in a lot of files that I have but I wanna ignore the cases when this substring is preceded by a letter or a…
RobertoH
  • 21
  • 2
2
votes
1 answer

count substrings of a string with limitation

I have a string and a dictionary. I need to count number of substrings of a given string that has letters(and number of letters) not more than in the dict. I counted only 15 substrings(2a +4b +1d + 2ba + 2ab +bd +db +abc +dba) but I cannot write the…
2
votes
2 answers

How to extract characters from a left of a substring and right of the same substring in PySpark column?

My Pyspark dataframe is something like this: |ID|A| +--+-------+ |1|7800028| |2|700024| |3|720004| |4|70004| |5|700004| I want to remove the 3 zeros occurring together and get numbers to the left and right of the three zeroes in separate…
2
votes
2 answers

Using std::search to search substrings in a std::string

I want to search in a string some substrings using std::search. I tried this: std::string str = "the quick brown fox jumps over the lazy dog"; std::string substr[] = { "fox","dog","bear" }; auto it = std::search(str.begin(), str.end(), substr,…
Ac1234
  • 67
  • 6
2
votes
1 answer

Why my thymeleaf #strings is not working?

There is a table on the html that I'm working on, and for one column I want to show up to 30 characters (because it can be very long). Below is my code but it's not working and I cannot figure out why. Any suggestion will be appreciated. Thank you…
eloise
  • 21
  • 2
2
votes
2 answers

Python extract string starting with index up to character

Say I have an incoming string that varies a little: " 1 |r|=1.2e10 |v|=2.4e10" " 12 |r|=-2.3e10 |v|=3.5e-04" "134 |r|= 3.2e10 |v|=4.3e05" I need to extract the numbers (ie. 1.2e10, 3.5e-04, etc)... so I would like to start at the end of '|r|' and…
Sam Grant
  • 432
  • 2
  • 7
  • 19
2
votes
2 answers

How to pass multiple delimiters to a substring (Kotlin/Android)?

I'm trying to make a calculator app, and I need to be able to get the last value after someone presses an operator (+,*,-,/) after the second time (the first value is saved with no issues since it's the only number on the screen). So if the top of…
actionjump
  • 23
  • 5
2
votes
4 answers

Swift: Extract a Substring from a String

I have a String that can be either of the following: tempString = "What? The ID: 54673 Over there" tempString = "Jump... ID: 4561E how high" Basically, I want to retrieve the five character ID: from the string. I can do this with most languages by…
NY Reno
  • 83
  • 6
2
votes
2 answers

Unwrapping a skipped Chars iterator

Many iterator methods is Rust generate iterators wrapped up in iterators. One such case is the skip method, that skips the given number of elements and yields the remaining ones wrapped in the Skip struct that implements the Iterator trait. I would…
sesodesa
  • 1,473
  • 2
  • 15
  • 24
2
votes
2 answers

Number of substrings of a string with given count of each character

Given a string (s) and an integer k, we need to find number of sub strings in which all the different characters occurs exactly k times. Example: s = "aabbcc", k = 2 Output : 6 The substrings [aa, bb, cc, aabb, bbcc and aabbcc] contains distinct…
2
votes
1 answer

Are there multiple KMP algorithmic approaches with different space complexities? What is the difference?

I am reading about the KMP substring search algorithm and the examples I find online use an one-dimensional table to build the prefix information table. I also read the Sedgewick explanation and he used a 2-D array to build the table and explicitly…
Jim
  • 3,845
  • 3
  • 22
  • 47
2
votes
1 answer

Replace random substring in JavaScript

I am trying to replace random substring with another within a string. This is my code function replaceRandomSubstring(str, substr, repl) { var amount = str.match(substr) var newstr = str; if (amount.length != -1) { var index =…
2
votes
1 answer

Handle multiple substrings in Woocommerce validation checkout form

a few years ago someone added code to our website (Wordpress/Woocommerce Checkout), which validates a field against a prefix and field length. The field validation code looks like this: add_action('woocommerce_checkout_process',…
Lord_iMac
  • 23
  • 3