MATLAB string processing functions

Source: Internet
Author: User
Tags integer numbers strtok

% String processing
A = 'a'; B = 'B'; C = 'cccccc'; M =''
% Get String Length
Length()
% Connects two strings. the rightmost space of each string is trimmed.
D =Strcat(A, c)
Length (d)
% Connects multiple lines of strings. The length of each line can be different. the rightmost side of the non-longest string is automatically filled with spaces.
% Equal to the longest string, the Null String is ignored
E =Strvcat(A, B, m)
Size (E)
% Char connection, empty strings will be filled with spaces
F =Char(A, B, m)
Size (f)

%StrcmpChecks whether two strings are completely equal. Yes, returns true. Otherwise, returns false.
%StrncmpChecks whether the first n characters of two strings are equal. If yes, true is returned. Otherwise, false is returned.
%StrcmPi compares the two strings to see if they are completely equal, ignoring uppercase and lowercase letters
%StrncmpiChecks whether the first n characters of two strings are equal. case insensitive.

%IsletterIndicates whether each character in a string belongs to an English letter.
%IsspaceChecks whether each character in a string belongs to a format character (space, carriage return, tabulation, line break, etc)
%IsstrpropChecks whether each character belongs to a specified range.
A = 'd sdsd 15 #';
B = isletter ()
C = isspace ()

% String replacement and search
%StrrepString replacement, case sensitive
% Strrep (str1, str2, str3)
% It replaces all str2 strings in str1 with str3

%Strfind(STR, Patten) Check if 'str' contains 'pattern' and return the location where it appears. No empty array is returned.
%Findstr(Str1, str2) in str1 and str2, the position where the shorter string appears in the longer string. No empty array is returned.
%Strmatch(Patten, STR) Check whether Patten is consistent with the leftmost part of Str.
%Strtok(STR, char) returns the part before and after the string specified by char in Str,
Mm = 'youqwelcome ';
[MM1, mm2] = strtok (mm, 'q ')

%Blanks(N) Create a string consisting of n Spaces
%Deblank(STR) trim the trailing space of a string
%Strtrim(STR) trim the spaces at the beginning and end of a string, tabulation, and carriage return.

%Lower(STR) converts letters in a string to lowercase letters.
%Upper(STR) converts the letters in the string to uppercase.
%Sort(STR) sorts strings by their ASCII values.

%Num2strConvert a number to a numeric string
%Str2numConverts a numeric string to a numeric string.
%Mat2strConverts an array to a string.
%Int2strConverts a numeric array to a character array composed of integer numbers.

------------------------------

String comparison in cell array:

C = cell (2, 1 );
C (1, 1) = cellstr ('xxx ');
C (2, 1) = cellstr ('yyyyy ');
Strcmp (c {1, 1}, c {2, 1 });

------------------------------

IsequalTest Arrays for equal ity can be used to compare whether the two character arrays are the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.