Main Content

La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.

Caractères et chaînes de caractères

Texte dans les tableaux de caractères et de chaînes de caractères

Les tableaux de caractères et de chaînes de caractères permettent le stockage de données texte dans MATLAB®.

  • Un tableau de caractères est une séquence de caractères, de même qu’un tableau numérique est une séquence de nombres. Une utilisation courante consiste à stocker de petits fragments de texte sous forme de vecteurs de caractères, par exemple c = 'Hello World'.

  • Un tableau de chaînes de caractères est un conteneur de fragments de texte. Les tableaux de chaînes de caractères proposent un ensemble de fonctions permettant de traiter les textes comme des données. Vous pouvez créer des chaînes en utilisant des guillemets anglais, par exemple str = "Greetings friend". Pour convertir des données en tableaux de chaînes de caractères, utilisez la fonction string.

Pour plus d’informations, consultez Text in String and Character Arrays ou regardez la vidéo Using String Arrays for Text Data (Utiliser des tableaux de chaînes de caractères pour les données texte).

Fonctions

développer tout

Tableaux de chaînes de caractères

stringString array
stringsCreate string array with no characters
joinCombine strings
plusAdd numbers, append strings

Tableaux de caractères

charCharacter array
cellstrConvert to cell array of character vectors
blanksCreate character array of blanks
newlineCréer un caractère de retour à la ligne

Tableaux de caractères ou de chaînes de caractères

composeFormat data into multiple strings
sprintfFormat data into string or character vector
strcatConcaténer les chaînes de caractères horizontalement
appendCombine strings (depuis R2019a)

Conversion des arguments en entrée

convertCharsToStringsConvert character arrays to string arrays, leaving other arrays unaltered
convertStringsToCharsConvert string arrays to character arrays, leaving other arrays unaltered
convertContainedStringsToCharsConvert string arrays at any level of cell array or structure

Conversion entre données numériques et chaînes de caractères

doubleTableaux en double précision
stringString array
str2doubleConvert strings to double precision values
num2strConvert numbers to character array

Type de données

ischarDetermine if input is character array
iscellstrDetermine if input is cell array of character vectors
isstringDetermine if input is string array
isStringScalar Determine if input is string array with one element

Propriétés du texte

strlengthLengths of strings
isstrpropDetermine which characters in input strings are of specified category
isletterDetermine which characters are letters
isspaceDetermine which characters are space characters

Rechercher

containsDetermine if pattern is in strings
matchesDetermine if pattern matches strings (depuis R2019b)
countCount occurrences of pattern in strings
endsWithDetermine if strings end with pattern
startsWithDetermine if strings start with pattern
strfindFind strings within other strings
sscanfRead formatted data from strings

Remplacer

replaceFind and replace one or more substrings
replaceBetweenReplace substrings between start and end points
strrepFind and replace substrings

Créer des patterns

patternPatterns to search and match text (depuis R2020b)

Patterns de correspondance de caractères

alphanumericsPatternMatch letter and digit characters (depuis R2020b)
characterListPatternMatch characters from list (depuis R2020b)
digitsPattern Match digit characters (depuis R2020b)
lettersPatternMatch letter characters (depuis R2020b)
whitespacePatternMatch whitespace characters (depuis R2020b)
wildcardPatternMatches as few characters of any type (depuis R2020b)

Règles de recherche de patterns

optionalPatternMake pattern optional to match (depuis R2020b)
possessivePatternMatch pattern without backtracking (depuis R2020b)
caseSensitivePatternMatch pattern with case sensitivity (depuis R2020b)
caseInsensitivePatternMatch pattern regardless of case (depuis R2020b)
asFewOfPatternMatch pattern as few times as possible (depuis R2020b)
asManyOfPatternMatch pattern as many times as possible (depuis R2020b)

Patterns de limites

alphanumericBoundaryMatch boundary between alphanumeric and non-alphanumeric characters (depuis R2020b)
digitBoundaryMatch boundary between digit characters and non-digit characters (depuis R2020b)
letterBoundaryMatch boundary between letter characters and non-letter characters (depuis R2020b)
whitespaceBoundaryMatch boundary between whitespace characters and non-whitespace characters (depuis R2020b)
lineBoundaryMatch start or end of line (depuis R2020b)
textBoundaryMatch start or end of text (depuis R2020b)
lookAheadBoundaryMatch boundary before specified pattern (depuis R2020b)
lookBehindBoundaryMatch boundary following specified pattern (depuis R2020b)

Affichage personnalisé des patterns

maskedPatternPattern with specified display name (depuis R2020b)
namedPatternDesignate named pattern (depuis R2020b)

Expressions régulières

regexpMatch regular expression (case sensitive)
regexpiMatch regular expression (case insensitive)
regexprepReplace text using regular expression
regexptranslateTranslate text into regular expression
regexpPatternPattern that matches specified regular expression (depuis R2020b)
joinCombine strings
plusAdd numbers, append strings
splitSplit strings at delimiters
splitlinesSplit strings at newline characters
strjoinJoin strings in array
strsplitSplit string or character vector at specified delimiter
strtokSelected parts of strings
extractExtract substrings from strings (depuis R2020b)
extractAfterExtract substrings after specified positions
extractBeforeExtract substrings before specified positions
extractBetweenExtract substrings between start and end points
eraseDelete substrings within strings
eraseBetweenDelete substrings between start and end points
extractExtract substrings from strings (depuis R2020b)
extractAfterExtract substrings after specified positions
extractBeforeExtract substrings before specified positions
extractBetweenExtract substrings between start and end points
insertAfterInsert strings after specified substrings
insertBeforeInsert strings before specified substrings
padAdd leading or trailing characters to strings
stripRemove leading and trailing characters from strings
lowerConvert strings to lowercase
upperConvert strings to uppercase
reverseReverse order of characters in strings
deblankRemove trailing whitespace from ends of strings
strtrimRemove leading and trailing whitespace from strings
strjustJustify strings
matchesDetermine if pattern matches strings (depuis R2019b)
strcmpCompare strings
strcmpiCompare strings (case insensitive)
strncmpCompare first n characters of strings (case sensitive)
strncmpiCompare first n characters of strings (case insensitive)

Rubriques