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

Trying to extract the substring of a string until the string's first number

I am trying to extract the substring of a string until the string's first number. var notes = ["D4", "F#8", "Abb2"]; note[0].substring(0,notes[0].indexOf(4); //returns D, gets rid of 1 However, this only works if the first number is 4. Other items…
Nakul Tiruviluamala
  • 523
  • 1
  • 3
  • 15
2
votes
1 answer

replace a substring of a given string in c++

I have a code to replace the content of a sub-string of a given string. It does not work as I expected. From my understanding, s3.find("they") would return 6. Since pos is not the same as string::npos, then, from position 6, 2 characters in s3 are…
kkxx
  • 571
  • 1
  • 5
  • 16
2
votes
7 answers

Looking for the easiest way to extract an unknown substring from within a string. (terms separated by slashes)

The initial string: initString = '/digital/collection/music/bunch/of/other/stuff' What I want: music Specifically, I want any term (will never include slashes) that would come between collection/ and /bunch How I'm going about…
James B
  • 432
  • 5
  • 22
2
votes
4 answers

finding the most amount of times a substring appears successively in a string

I have a long string of characters and not only am I trying to find if a substring of those characters exists within the larger string, I'm also trying to find the longest run of successive instances. For example... in the code snippet below I've…
2
votes
1 answer

how to put php code inside a jquery function

i want to put a link "Read more" in a div 'guest-message' when the number of characters is more then 300. In the link are some php variables:
john
  • 1,263
  • 5
  • 18
2
votes
2 answers

What is best way to search a text to determine if it contains the word (or words) I am searching for?

If it was just searching for a single word, it would have been easy, but the needle can be a word or more than a word. Example $text = "Dude,I am going to watch a movie, maybe 2c Rio 3D or Water for Elephants, wanna come over"; $words_eg1 = array…
Andy W.
  • 21
  • 1
2
votes
3 answers

How to get multiple Substrings of the same Index?

I want to extract every Area between and . Since I write a code generator I can't define how often it is present because it can be different with every xml. I just get null pointers when executing so what do I do…
Trinity
  • 69
  • 5
2
votes
3 answers

how to split a string with both space and special characters in oracle?

I want to split the string by space and with special characters if any. Ex: For expressing mobile switching center (signal strength). Currently I am using the regex to split the string and I am not able to achieve both space and special characters…
ABY
  • 393
  • 2
  • 11
2
votes
2 answers

parsing substring from variable with ansible

I have this snipplet: --- - hosts: all gather_facts: False become: yes become_user: somesu become_method: sudo tasks: - set_fact: tmped: "{{varput | regex_search('(^(?:[^.]*.){4}([^.]*))')}}" - debug: msg="{{ tmped…
arenginsm na
  • 141
  • 1
  • 8
2
votes
1 answer

Find Sub string in SSRS and evaluate or replace

In SSRS I have data field called Event_dt it returns as Digital followed by Month, then Year. It looks like this Digital January 2021 or Digital May 2019 Question 1: In one field - I need to truncate the word Digital so the string would only read…
YelizavetaYR
  • 1,611
  • 6
  • 21
  • 37
2
votes
3 answers

Extract all substrings meeting criteria using R regex

I have an extremely long string in R and would like to extract all substrings that match a certain criteria. The string may look something like this: "some text some text some text [ID: 1234] some text some text [ID: 5678] some text some text [ID:…
Jordan Hackett
  • 689
  • 3
  • 11
2
votes
1 answer

Substring a statement after character matching and year

I am trying to extract certain rows based on year from my dataset, furthermore I want to substring those rows matching the following conditions, for year 2017 I want to substring the the portion before the second '-' in the statment for eg:…
2
votes
2 answers

Explode on semicolons, isolate first word of each element, then implode

I have a string of values that are trailed by carets and groups of words are separated by semicolons. I tried to split the string on semicolons, but I only want the first word after each semicolon without its trailing caret. $myString =…
2
votes
1 answer

How to use a SQL query in Google Sheets to group by a substring

In my table, in Google Sheets, I have a column B called "description" and I'm trying to write a SQL query to group by substrings of column B. Values in B are like "Sell 1 Jan11 300.0/307.5 Strangle" and I just want to group by 'Jan11'. I have a few…
ajg
  • 59
  • 1
  • 6
2
votes
3 answers

Match Characters after last dot in string

I have a string and I want to get the words after the last dot . in the string. Example: string input = "XimEngine.DynamicGui.PickKind.DropDown"; Result: DropDown
Andrei Călugăr
  • 143
  • 1
  • 3
  • 14