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
4 answers

Java: How to RegEx or Substring Utils this String?

"Current Peak : 830 300" How can I get hold of the two numbers, but without the spaces. (There are 5 or more spaces in between each substring) Using apache's StringUtils I got so far: String workUnit…
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
2
votes
2 answers

how to give multiple values in substring condition used in awk

My input file has below values, 93401140232 93403047213 93443757143 93451675101 93473360818 93451495679 93403707762 93403966944 93441513846 93472692526 I want to result only the "93441","93443","93451","93472" prefixes from the list. i thought of…
ramki_ramakrishnan
  • 169
  • 1
  • 1
  • 9
2
votes
1 answer

How to replace a specific character in a substring using regex?

My objective This question is about Visual Studio Code search box. I want to replace all the "spaces" by the character "_" inside the my substring with spaces of mystring for example: -> From { "Show_details": mystring("my substring with…
Mike Casan Ballester
  • 1,690
  • 19
  • 33
2
votes
2 answers

Shorten a variable long file name by strings in the front and end

I want to shorten this file name from '210 8th Waverly Updated Submittal (#26 0100-15.0 260100-015.00 - Short Circuit & Protective Device Coordination Study (For Rushing Review)).txt' to '26 0100-15.0 260100-015.00 - Short Circuit & Protective…
markus1998
  • 23
  • 5
2
votes
2 answers

Deleting all text starting with a specific string in a pandas series

I've got the following df called "places" place_name 0 "Palais et bâtiments officiels[modifier | modifier le code]" 1 "Lieux de culte renommés[modifier | modifier le code]" 2 …
aramis
  • 85
  • 7
2
votes
4 answers

Help checking if number value in string is odd C#

I have the method GetOption(5) that returns the value 5K23 and I need to get the last two characters of the string the thing is the value is a string value, so I would need to use Substring I have tried doing: if(…
Sandeep Bansal
  • 6,280
  • 17
  • 84
  • 126
2
votes
2 answers

Cut substring on multiple columns when one column contains a particular substring

I want to cut a certain part of a string (applied to multiple columns and differs on each column) when one column contains a particular substring Example: Assume the following dataframe import pandas as pd df =…
davvpo
  • 39
  • 3
2
votes
0 answers

Unexpected Output through \r carriage return

var t2 = "\tMohamed\rMazen \n \tof \rMastering\n\t\t\programming"; console.log(t2); The output using JavaScript is: Mohamed Mazen of Mastering programming Shouldn't it be: Mazen mohamed Mastering of programming…
2
votes
4 answers

T SQL how to modify a string by removing all the part after the last delimiter

I'm struggling to find the right functions with SQL Server 2008 to rectify any strings coming like: \\myserver\mydir1\dir2\test.txt or \\myserver2\dir1\dir2\dir3\test.txt. At the end, the result should appear like: \\myserver\mydir1\dir2 or…
largo68
  • 609
  • 2
  • 16
  • 29
2
votes
3 answers

How to find a word in string not a substring

Is there any function for finding an exact word in string? char *str = "My birthday is 32.32.2133"; char *new = strstr(str, "day"); So, in (new) i got a pointer on 'd' symbol in (str). But I need a pointer not to a substring, but to a word in a…
2
votes
1 answer

How to extract a variable length substring using ksh

I need to extract a variable length sub string using Korn shell on Linux. Sample String: "SID_LIST_ORADBPOC1LSN =" Need to extract substring: "ORADBPOC1LSN" Note: The sample substring is of variable length. Thanks in advance. FR
user13708337
  • 97
  • 1
  • 1
  • 7
2
votes
1 answer

Correct Use of the SQL String_Split and Substring function

I have the SQL code below, where the @Province input parameter is in this form: "[""Central District","Central Region","Delaware","Drenthe","Eastern Cape","Free State","Gauteng","Hardap Region","Haryana","Karas Region","KwaZulu…
2
votes
2 answers

How to count number of occurrences of a substring inside a string in Python?

I am attempting to write a code snippet that requests from the user to enter a string s and then a substring ss. The program will then have to count the number of occurrences of ss in s. For example if the user enters s = ‘azcbobobegghakl’ and ss =…
2
votes
1 answer

Select where string contains substring using Panache

I'm currently trying to implement the function "Load all X where X.name contains y" using a Ms SQL-Server and the Panache-Repositories. I know the SQL-Query "SELECT * FROM X WHERE X.name LIKE '%0y%'" works, but I can't get it to work using the…
Urr4
  • 611
  • 9
  • 26
2
votes
2 answers

How to generate a warning/error when using non-string-variables inside string interpolation?

TypeScript does not produce any errors for the following code: const maybe_a_string: undefined | string = undefined; const false_or_string: false | string = false; // I'd like the following to produce an error/warning... const message_string =…
LaVache
  • 2,372
  • 3
  • 24
  • 38