I apologize if this is a newb question, but I have read the documentation here and it says nothing about having to input any command before using substring.
However, when I try to call it as follows:
substring('hello world', 2)
It gives me the error
??? Undefined function or method 'substring' for input arguments of type 'char'.
What is the correct way to invoke this substring
?
tf = contains( str , substr ) returns 1 ( true ) if the string str contains the substring substr , and returns 0 ( false ) otherwise. tf = contains( str , substr ,IgnoreCase=true) checks if str contains substr , ignoring any differences in letter case.
newStr = split( str ) divides str at whitespace characters and returns the result as the output array newStr . The input array str can be a string array, character vector, or cell array of character vectors. If str is a string array, then so is newStr .
Concatenate Two String Arrays Strings and character vectors can be combined using strcat . When concatenating strings with character vectors a whitespace will not be added. Concatenate a character vector onto each element of the string array. str3 = strcat(str,', M.D.')
String arrays provide a set of functions for working with text as data. You can create strings using double quotes, such as str = "Greetings friend" . To convert data to string arrays, use the string function.
Not to detract from the OP's answer, which actually more directly adresses the question you ask, but assuming all you want to do is extract a certain number of characters from a string, MATLAB's indexing is all you need:
myString = 'Hello, world!';
mySubstring = myString(3:end)
mySubstring =
llo, world!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With