Documentation

extractAfter

Extract substring after specified position

Syntax

newStr = extractAfter (str, startStr)
newStr = extractAfter (str, startPos)

Description

example

newStr= extractAfter(str,startStr)extracts the substring that begins afterstartStrand ends with the last character ofstr. IfstartStroccurs multiple times instr, thennewStrisstrfrom the first occurrence ofstartStrto the end.

Ifstris a string array or a cell array of character vectors, thenextractAfterextracts substrings from each element ofstr. The output argumentnewStrhas the same data type asstr.

example

newStr= extractAfter(str,startPos)extracts the substring that begins after the position specified bystartPosand ends with the last character ofstr.

Examples

collapse all

Create string arrays and select text that occurs after substrings.

Starting in R2017a, you can create strings using double quotes instead of thestringfunction.

str ="The quick brown fox"
str = "The quick brown fox"

Extract the substring that occurs after the substring“快”. TheextractAfterfunction selects the new text but does not include“快”in the output.

newStr = extractAfter(str,“快”)
newStr = "brown fox"

Create a new string array from the elements of a string array. When you specify different substrings as positions, they must be contained in a string array or a cell array that is the same size as the input string array.

str = ["The quick brown fox jumps";"over the lazy dog"]
str =2x1 string array"The quick brown fox jumps" "over the lazy dog"
newStr = extractAfter(str,[“快”;"the "])
newStr =2x1 string array"brown fox jumps" "lazy dog"

You also can specify one substring as a position that is applied to all elements of the input string array.

Create strings after specified positions.

Starting in R2017a, you can create strings using double quotes instead of thestringfunction.

str ="Edgar Allen Poe"
str = "Edgar Allen Poe"

Select the substring after the 12th character.

newStr = extractAfter(str,12)
newStr = "Poe"

Select substrings from each element of a string array. When you specify different positions with numeric arrays, they must be the same size as the input string array.

str = ["Edgar Allen Poe";"Louisa May Alcott"]
str =2x1 string array"Edgar Allen Poe" "Louisa May Alcott"
newStr = extractAfter(str,[12;11])
newStr =2x1 string array"Poe" "Alcott"

Select substrings from each element and specify the same position.

newStr = extractAfter(str,6)
newStr =2x1 string array"Allen Poe" " May Alcott"

Create a character vector. Then create new character vectors that are substrings ofchr.

chr ='peppers and onions'
chr = 'peppers and onions'

Select text after the 12th position.

newChr = extractAfter(chr,12)
newChr = 'onions'

Select text after a substring.

newChr = extractAfter(chr,'and ')
newChr = 'onions'

Input Arguments

collapse all

Input text, specified as a string array, a character vector, or a cell array of character vectors.

Data Types:string|char|cell

String that indicates the start of the substring to extract, specified as a string array, a character vector, or a cell array of character vectors.extractAfterexcludesstartStrfrom the substring to extract.

Ifstris a string array or cell array of character vectors, thenstartStrcan be a character vector, a string scalar, or a string array or a cell array of the same size asstr.

Data Types:string|char|cell

Start position of substring to extract, specified as a numeric array.extractAfterexcludes the character atstartfrom the substring to extract.

Ifstris a string array or cell array of character vectors, thenstartPoscan be a numeric scalar or a numeric array of the same size asstr.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Output Arguments

collapse all

Output text, returned as a string array, a character vector, or a cell array of character vectors.

Data Types:string|char|cell

Extended Capabilities

Introduced in R2016b

Was this topic helpful?