Main Content

Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

Caracteres y cadenas

Texto en arreglos de caracteres y arreglos de cadenas

Los arreglos de caracteres y los arreglos de cadenas sirven para almacenar datos de texto en MATLAB®.

  • Un arreglo de caracteres es una secuencia de caracteres, así como un arreglo numérico es una secuencia de números. Comúnmente, se utiliza para almacenar pequeños fragmentos de texto como vectores de caracteres (por ejemplo, c = 'Hello World').

  • Un arreglo de cadenas es un contenedor de fragmentos de texto. Los arreglos de cadenas proporcionan un conjunto de funciones para trabajar con texto como datos. A partir de la versión R2017a, es posible crear cadenas con comillas dobles, como str = "Greetings friend". Para convertir datos en arreglos de cadenas, use la función string.

Para obtener más información, consulte Text in String and Character Arrays o vea Uso de arreglos de cadenas para datos de texto.

Funciones

expandir todo

Arreglos de cadenas

stringArray de cadenas 
stringsCreate string array with no characters
joinCombine strings

Arreglos de caracteres

charArray de caracteres
cellstrConvert to cell array of character vectors
blanksCreate character array of blanks
newlineCreate newline character

Arreglos de caracteres o cadenas

composeFormat data into multiple strings
sprintfFormatear datos en cadena
strcatConcatenar cadenas horizontalmente
appendCombine strings

Convertir argumentos de entrada

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

Convertir entre valores numéricos y cadenas

doubleDouble-precision arrays
stringArray de cadenas 
str2doubleConvert strings to double precision values
num2strConvertir números a array de caracteres

Tipo de datos

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

Propiedades de texto

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

Buscar

containsDetermine if pattern is in strings
matchesDetermine if pattern matches strings
countCount occurrences of pattern in strings
endsWithDetermine if strings end with pattern
startsWithDetermine if strings start with pattern
strfindEncontrar una cadena dentro de otro
sscanfRead formatted data from strings

Reemplazar

replaceFind and replace one or more substrings
replaceBetweenReplace substrings between start and end points
strrepFind and replace substrings
joinCombine strings
splitSplit strings at delimiters
splitlinesSplit strings at newline characters
strjoinJoin strings in array
strsplitCadena dividida en delimitador especificado
strtokSelected parts of strings
eraseDelete substrings within strings
eraseBetweenDelete substrings between start and end points
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
strcmpComparar cadenas
strcmpiCompare strings (case insensitive)
strncmpCompare first n characters of strings (case sensitive)
strncmpiCompare first n characters of strings (case insensitive)
regexpMatch regular expression (case sensitive)
regexpiMatch regular expression (case insensitive)
regexprepReplace text using regular expression
regexptranslateTranslate text into regular expression

Temas

Text in String and Character Arrays

Store and manipulate text using either string arrays or character arrays.

Update Your Code to Accept Strings

Adopt string arrays as a text data type in your own code, following these guidelines.

Analyze Text Data with String Arrays

This example shows how to analyze text data with string arrays. It shows how to store, split, and sort text, and how to compute and collect statistics for text in a string array.

Formatting Text

Compose character arrays or string arrays that include ordinary text and data formatted to your specification.

Hexadecimal and Binary Values

Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.

Unicode and ASCII Values

MATLAB stores all characters as Unicode characters. Both strings and character vectors use the same encoding. You can convert characters to their Unicode code values, and numbers to characters.

Expresiones regulares

Las expresiones regulares son una forma versátil de buscar y reemplazar texto.