Text in Character und String Arrays
Character und String Arrays stellen Speicherplatz für Textdaten in MATLAB® bereit.
Ein Character Array (Zeichenarray) ist eine Zeichenfolge, genauso wie ein numerisches Array eine Zahlenfolge ist. Es wird typischerweise dazu verwendet, kurze Textbausteine als Zeichenvektoren, wie
c = 'Hello World'
, zu speichern.Ein String Array (Zeichenfolgenarray) ist ein Container für Textbausteine. String Arrays stellen eine Reihe von Funktionen bereit, um mit Texten als Daten zu arbeiten. Sie können Zeichenfolgen mit Anführungszeichen, wie
str = "Greetings friend"
, erstellen. Mit der Funktion string konvertieren Sie Daten in String Arrays.
Weitere Informationen finden Sie unter Text in String and Character Arrays oder sehen Sie sich Verwenden von String Arrays für Textdaten an.
Funktionen
alle erweitern
Erstellen, Verknüpfen und Konvertieren
String Arrays
string | String array |
strings | Create string array with no characters |
join | Combine strings |
plus | Add numbers, append strings |
Character Arrays
char | Character array |
cellstr | Convert to cell array of character vectors |
blanks | Create character array of blanks |
newline | Erstellen des Zeichens für eine neue Zeile |
Character oder String Arrays
compose | Format data into multiple strings |
sprintf | Format data into string or character vector |
strcat | Horizontales Verknüpfen von Zeichenfolgen |
append | Combine strings |
Konvertieren von Eingabeargumenten
convertCharsToStrings | Convert character arrays to string arrays, leaving other arrays unaltered |
convertStringsToChars | Convert string arrays to character arrays, leaving other arrays unaltered |
convertContainedStringsToChars | Convert string arrays at any level of cell array or structure |
Konvertieren zwischen Zahlen und Zeichenfolgen
double | Arrays mit doppelter Genauigkeit |
string | String array |
str2double | Convert strings to double precision values |
num2str | Convert numbers to character array |
Festlegen von Typ und Eigenschaften
Datentyp
ischar | Determine if input is character array |
iscellstr | Determine if input is cell array of character vectors |
isstring | Determine if input is string array |
isStringScalar | Determine if input is string array with one element |
Texteigenschaften
strlength | Lengths of strings |
isstrprop | Determine which characters in input strings are of specified category |
isletter | Determine which characters are letters |
isspace | Determine which characters are space characters |
Suchen und Ersetzen
Suchen
contains | Determine if pattern is in strings |
matches | Determine if pattern matches strings (Seit R2019b) |
count | Count occurrences of pattern in strings |
endsWith | Determine if strings end with pattern |
startsWith | Determine if strings start with pattern |
strfind | Find strings within other strings |
sscanf | Read formatted data from strings |
Ersetzen
replace | Find and replace one or more substrings |
replaceBetween | Replace substrings between start and end points |
strrep | Find and replace substrings |
Musterabgleich
Erstellen von Mustern
pattern | Patterns to search and match text (Seit R2020b) |
Zeichen-Musterabgleich
alphanumericsPattern | Match letter and digit characters (Seit R2020b) |
characterListPattern | Match characters from list (Seit R2020b) |
digitsPattern | Match digit characters (Seit R2020b) |
lettersPattern | Match letter characters (Seit R2020b) |
whitespacePattern | Match whitespace characters (Seit R2020b) |
wildcardPattern | Matches as few characters of any type (Seit R2020b) |
Muster-Suchregeln
optionalPattern | Make pattern optional to match (Seit R2020b) |
possessivePattern | Match pattern without backtracking (Seit R2020b) |
caseSensitivePattern | Match pattern with case sensitivity (Seit R2020b) |
caseInsensitivePattern | Match pattern regardless of case (Seit R2020b) |
asFewOfPattern | Match pattern as few times as possible (Seit R2020b) |
asManyOfPattern | Match pattern as many times as possible (Seit R2020b) |
Grenzwert-Muster
alphanumericBoundary | Match boundary between alphanumeric and non-alphanumeric characters (Seit R2020b) |
digitBoundary | Match boundary between digit characters and non-digit characters (Seit R2020b) |
letterBoundary | Match boundary between letter characters and non-letter characters (Seit R2020b) |
whitespaceBoundary | Match boundary between whitespace characters and non-whitespace characters (Seit R2020b) |
lineBoundary | Match start or end of line (Seit R2020b) |
textBoundary | Match start or end of text (Seit R2020b) |
lookAheadBoundary | Match boundary before specified pattern (Seit R2020b) |
lookBehindBoundary | Match boundary following specified pattern (Seit R2020b) |
Benutzerdefinierte Musteranzeige
maskedPattern | Pattern with specified display name (Seit R2020b) |
namedPattern | Designate named pattern (Seit R2020b) |
Reguläre Ausdrücke
regexp | Match regular expression (case sensitive) |
regexpi | Match regular expression (case insensitive) |
regexprep | Replace text using regular expression |
regexptranslate | Translate text into regular expression |
regexpPattern | Pattern that matches specified regular expression (Seit R2020b) |
Verbinden und Aufteilen
join | Combine strings |
plus | Add numbers, append strings |
split | Split strings at delimiters |
splitlines | Split strings at newline characters |
strjoin | Join strings in array |
strsplit | Split string or character vector at specified delimiter |
strtok | Selected parts of strings |
extract | Extract substrings from strings (Seit R2020b) |
extractAfter | Extract substrings after specified positions |
extractBefore | Extract substrings before specified positions |
extractBetween | Extract substrings between start and end points |
Bearbeiten
erase | Delete substrings within strings |
eraseBetween | Delete substrings between start and end points |
extract | Extract substrings from strings (Seit R2020b) |
extractAfter | Extract substrings after specified positions |
extractBefore | Extract substrings before specified positions |
extractBetween | Extract substrings between start and end points |
insertAfter | Insert strings after specified substrings |
insertBefore | Insert strings before specified substrings |
pad | Add leading or trailing characters to strings |
strip | Remove leading and trailing characters from strings |
lower | Convert strings to lowercase |
upper | Convert strings to uppercase |
reverse | Reverse order of characters in strings |
deblank | Remove trailing whitespace from ends of strings |
strtrim | Remove leading and trailing whitespace from strings |
strjust | Justify strings |
Vergleichen
matches | Determine if pattern matches strings (Seit R2019b) |
strcmp | Compare strings |
strcmpi | Compare strings (case insensitive) |
strncmp | Compare first n characters of strings(case sensitive) |
strncmpi | Compare first n characters of strings(case insensitive) |
Themen
- Text in String and Character Arrays
Store and manipulate text using either string arrays or character arrays.
- Create String Arrays
- Frequently Asked Questions About String Arrays
- Update Your Code to Accept Strings
- Cell Arrays of Character Vectors
- Analyze Text Data with String Arrays
This example shows how to analyze text data with stringarrays. It shows how to store, split, and sort text, and how to computeand collect statistics for text in a string array.
- Compare Text
- Test for Empty Strings and Missing Values
- Formatting Text
Compose character arrays or string arrays that includeordinary text and data formatted to your specification.
- Search and Replace Text
MATLAB provides several functions to search for,replace, or extract text in string arrays and character vectors.
- Build Pattern Expressions
- Regular Expressions
- Lookahead Assertions in Regular Expressions
- Tokens in Regular Expressions
- Dynamic Regular Expressions
- 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.
- 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.
Verwandte Informationen
- Grundlagen der Programmierung (MathWorks Unterrichtsressourcen)
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office