less than 1 minute read



1.2.1 strings Datatype


지금까지는 문자열을 저장하는 배열에 char를 사용했다. 여기서는 strings 타입을 쓰자.

Strings 데이터 타입에는 여러 장점이 있다.


  (1) Manipulate, compare, storing이 용이하다.

"image" + (1:3) + ".png"

---

ans = 

  1×3 string 배열

    "image1.png"    "image2.png"    "image3.png"

  (2) Text manipulation 작업이 간단하다.

% string 내에 다른 string이 포함되었는지 확인하기.

% Previous code
if ~isempty(strfind(textdata, "Dog"))

% Use strings type
if contains(textdata, "Dog")


string 클래스에 대한 method들을 보고 싶다면

methods string

---
string 클래스에 대한 메서드:

append          double          extractAfter    insertBefore    lt              replace         startsWith      
cellstr         endsWith        extractBefore   ismissing       matches         replaceBetween  strip           
char            eq              extractBetween  issorted        ne              reverse         strlength       
compose         erase           ge              join            or              sort            upper           
contains        eraseBetween    gt              le              pad             split           
count           extract         insertAfter     lower           plus            splitlines      

  (3) 성능이 우수하다.

  • cellstr에서 strfind를 사용하는 것보다 string에서 contains를 사용하는 것이 50배 빠르다.

  • cellstr보다 string이 메모리를 2배 아낄 수 있다.