Main Content

La traduzione di questa pagina non è aggiornata. Fai clic qui per vedere l'ultima versione in inglese.

Caratteri e stringhe

Testo in array di caratteri e in array di stringhe

Gli array di caratteri e gli array di stringhe consentono di memorizzare i dati di testo in MATLAB®.

  • Un array di caratteri è una sequenza di caratteri così come un array numerico è una sequenza di numeri. Un uso tipico è quello di memorizzare brevi porzioni di testo come vettori di caratteri, come c = 'Hello World'.

  • Un array di stringhe è un contenitore per porzioni di testo. Gli array di stringhe forniscono un insieme di funzioni per lavorare con il testo come dati. È possibile creare stringhe utilizzando le virgolette doppie, come str = "Greetings friend". Per convertire i dati in array di stringhe, utilizzare la funzione string.

Per maggiori informazioni, vedere Text in String and Character Arrays o guardare Using String Arrays for Text Data (Utilizzo degli array di stringhe per i dati di testo).

Funzioni

espandi tutto

Array di stringhe

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

Array di caratteri

charCharacter array
cellstrConvert to cell array of character vectors
blanksCreate character array of blanks
newlineCreare il carattere nuova riga

Array di stringhe o di caratteri

composeFormat data into multiple strings
sprintfFormat data into string or character vector
strcatConcatenare le stringhe orizzontalmente
appendCombine strings (Da R2019a)

Conversione degli argomenti di input

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

Conversione tra numeri e stringhe

doubleArray a doppia precisione
stringString array
str2doubleConvert strings to double precision values
num2strConvert numbers to character array

Tipo di dati

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

Proprietà del testo

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

Ricerca

containsDetermine if pattern is in strings
matchesDetermine if pattern matches strings (Da 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

Sostituzione

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

Costruzione di pattern

patternPatterns to search and match text (Da R2020b)

Pattern di corrispondenza dei caratteri

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

Regole di ricerca dei pattern

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

Pattern del contorno

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

Personalizzazione della visualizzazione dei pattern

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

Espressioni regolari

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 (Da 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 (Da 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 (Da 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 (Da R2019b)
strcmpConfrontare stringhe
strcmpiCompare strings (case insensitive)
strncmpCompare first n characters of strings (case sensitive)
strncmpiCompare first n characters of strings (case insensitive)

Argomenti