String Functions

char

Conversion of a matrix to a string.

Syntax

s = char(M)
S = char(s1, s2, ...)

Description

char(M) converts the elements of matrix M to characters, resulting in a string of the same size.

char(s1,s2,...) concatenates vertically the strings given as arguments to produce a string matrix. If the strings do not have the same length, blanks are added to the right.

Examples

char(65:70)
  ABCDEF
char('ab','cde')
  ab
  cde
char('abc',['de';'fg'])
  abc
  de
  fg

See also

setstr, operator :, ischar, logical, double

findstr

Find a substring in a string.

Syntax

pos = findstr(str, sub)

Description

findstr(str,sub) finds occurrences of string sub in string str and returns a vector of the positions of all occurrences, or the empty vector [] if there is none. Occurrences may overlap.

Examples

findstr('ababcdbaaab','ab')
  1 3 10
findstr('ababcdbaaab','ac')
  []
findstr('aaaaaa','aaa')
  1 2 3

See also

find, strcmp

isletter

Test for letters.

Syntax

b = isletter(s)

Description

For each character of string s, isletter(s) is true if it is a letter and false otherwise. Letters with diacritical signs are not considered as letters.

Examples

isletter('abAB12* ')
  1 1 1 1 0 0 0 0
isletter([10 20 70])
  0 0 1

See also

isspace, ischar

isspace

Test for spaces.

Syntax

b = isspace(s)

Description

For each character of string s, isspace(s) is true if it is a space, a tabulator, a carriage return or a line feed, and false otherwise.

Example

isspace('a\tb c\nd')
  0 1 0 1 0 1 0

See also

isletter, ischar

ischar

Test for a string object.

Syntax

b = ischar(obj)

Description

ischar(obj) is true if the object obj is a character string, false otherwise. Strings can have more than one line.

Examples

ischar('abc')
  1
ischar(0)
  0
ischar([])
  0
ischar('')
  1
ischar(['abc';'def'])
  1

See also

isletter, isspace, isnumeric, islogical, islist, setstr, char

lower

Convert all uppercase letters to lowercase.

Syntax

s2 = lower(s1)

Description

lower(s1) converts all the uppercase letters of string s1 to lowercase. Currently, only ASCII letters (without diacritic) are converted.

Example

lower('abcABC123')
  abcabc123

See also

upper, isletter

setstr

Conversion of a matrix to a string.

Syntax

str = setstr(M)

Description

setstr(M) converts the elements of matrix M to characters, resulting in a string of the same size. Currently, the native character encoding is used.

Example

setstr(65:75)
  ABCDEFGHIJK

See also

char, logical, double

strcmp

String comparison.

Syntax

b = strcmp(s1, s2)
b = strcmp(s1, s2, n)

Description

strcmp(s1, s2) is true if the strings s1 and s2 are equal (i.e. same length and corresponding characters are equal). strcmp(s1, s2, n) compares the strings up to the n:th character. Note that this function does not return the same result as the strcmp function of the standard C library.

Examples

strcmp('abc','abc')
  1
strcmp('abc','def')
  0
strcmp('abc','abd',2)
  1
strcmp('abc','abc',5)
  1

See also

strcmpi, operator ===, operator ~==, operator ==, findstr

strcmpi

String comparison with ignoring letter case.

Syntax

b = strcmpi(s1, s2)
b = strcmpi(s1, s2, n)

Description

strcmpi compares strings for equality, ignoring letter case. In every other respect, it behaves like strcmp.

Examples

strcmpi('abc','aBc')
  1
strcmpi('Abc','abd',2)
  1

See also

strcmp, operator ===, operator ~==, operator ==, findstr

upper

Convert all lowercase letters to lowercase.

Syntax

s2 = upper(s1)

Description

upper(s1) converts all the lowercase letters of string s1 to uppercase. Currently, only ASCII letters (without diacritic) are converted.

Example

upper('abcABC123')
  ABCABC123

See also

lower, isletter


Copyright 1998-2001, Calerga.

All rights reserved.