In Octave GNU, A string is basically the collection of characters enclosed between double quotes (“) or single quotes (‘).
Example of strings
“This is a string”
‘This is also a string’
In Octave, there is no limit for the length of the string. i.e. It can be of any size. Character array is used to represent a string in Octave
Escape Sequence : Some double-quoted(“) string containing backslash(‘\’), change the meaning of that string constant, these types of strings are special and are used for special purposes. The backslash (‘\’) character is known as Escape Character.
Below is the list of some Escape Sequences
|Represents a literal backslash, ‘\’|
|Represents a literal double-quote character, ‘”‘|
|Represents a literal single-quote character, ”’|
|Represents the null character, ASCII code 0|
|Represents the “alert” character, ASCII code 7|
|Represents a backspace, ASCII code 8|
|Represents a formfeed, ASCII code 12|
|Represents a newline, ASCII code 10|
|Represents a carriage return, ASCII code 13|
|Represents a horizontal tab, ASCII code 9|
|Represents a vertical tab, ASCII code 11|
Represents the octal value nnn, where nnn are one to three digits between 0
Represents the hexadecimal value hh, where hh are hexadecimal digits (‘0’
through ‘9’ and either ‘A’ through ‘F’ or ‘a’ through ‘f’).
String creation in Octave
In the octave, a string can be generated by using the double quotes, single quotes, and
- Using Double Quotes : varA = “String”;
- Using Single Quotes : varB = ‘String’;
- Using blanks() : varC = blanks(10), create a 10 size string of blank equivalent to ” “
String concatenation in Octave
In the octave, there are two ways to concatenate strings
- Using Square Brackett ‘’ : newStr = [oldStr1 oldStr2]; or newStr = [oldStr1, oldStr2];
- Using strcat() : newStr = strcat(oldStr1, oldStr2);
String comparison in Octave
In the octave,
strcmp() is used to compare two strings
There are various versions of
- strcmp(s1, s2, n) : compares the first n characters of s1 with s2
- strcmpi(s1, s2) : case insensitive
Below is the octave code to demonstrate the above-mentioned functions and concepts
String created using " is : This is a string . String created using ' is : This is also a string . String created using blanks() is : . String Concatenation String Concatenation using [ ] is : firstlast . String Concatenation using [, ] is : firstlast . String Concatenation using strcat() is : firstlast . String Comparision Comparision using strcmp() : 0
- How to take input in Octave GNU?
- Comments in Octave GNU
- Switch case statement in Octave GNU
- How to output in Octave GNU
- Vectors in Octave GNU
- Basic Operations in Octave
- How to load and modify matrices and vectors in Octave?
- How to Perform Computational Operations in Octave?
- Loops (For and While) and Control Statements in Octave
- Octave - Basics of Plotting Data
- Difference Between MATLAB and Octave
- User Defined Data Structures in Octave
- Top Dying Programming Languages in 2020
- 6 Trending Programming Languages You Should Learn in 2020
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.