Subset a string

Viewed 39

It's easy to subset a character vector:

>> c = 'hello world';
>> c(1:5)

ans =

    'hello'

But that doesn't work for strings:

>> s = "hello world";
>> s(1:5)
Index exceeds the number of array elements (1).

How do I subset a string?

1 Answers

You can use the extractBetween function:

>> s = "hello world";
>> extractBetween(s, 1, 5)

ans = 

    "hello"
Related