Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 after startStr and ends with the last character of str. If startStr occurs multiple times in str, then newStr is str from the first occurrence of startStr to the end.

If str is a string array or a cell array of character vectors, then extractAfter extracts substrings from each element of str. The output argument newStr has the same data type as str.

example

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

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 the string function.

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

Extract the substring that occurs after the substring "quick ". The extractAfter function selects the new text but does not include "quick " in the output.

newStr = extractAfter(str,"quick ")
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 = 2×1 string array
    "The quick brown fox jumps"
    "over the lazy dog"

newStr = extractAfter(str,["quick ";"the "])
newStr = 2×1 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 the string function.

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 = 2×1 string array
    "Edgar Allen Poe"
    "Louisa May Alcott"

newStr = extractAfter(str,[12;11])
newStr = 2×1 string array
    "Poe"
    "Alcott"

Select substrings from each element and specify the same position.

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

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

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. extractAfter excludes startStr from the substring to extract.

If str is a string array or cell array of character vectors, then startStr can be a character vector, a string scalar, or a string array or a cell array of the same size as str.

Data Types: string | char | cell

Start position of substring to extract, specified as a numeric array. extractAfter excludes the character at start from the substring to extract.

If str is a string array or cell array of character vectors, then startPos can be a numeric scalar or a numeric array of the same size as str.

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?