String type

The string data type is a representation of string literals. Unlike in C, the string is a basic data type in Vue

Having a string type avoids some of the confusion in C which does not support a string type but permits a string to be represented both by a pointer to a char type and by a character array. You can explicitly declare a string variable by using the string declaration statement. Explicitly declared string variables must also specify the maximum string length (similar to how character arrays are declared in C). Unlike C, strings in Vue are not explicitly terminated by a null character and you do not need to reserve space for it.

   String s[40];		/* Defines a string 's' of length 40 */
   s = "probevue";

Further, any string literal written in C-style with enclosing double-quotes is automatically assigned a string data type. Vue automatically converts an external variable that is declared as a C-style character data type (char * or char[]) to the string data type as needed.

You can use the following operators for the string data type:

  • The concatenation operator: "+" .
  • The assignment operator: "=" .
  • Relative operators for comparing strings: "==", "!=", ">", ">=", "<" and "<=".

You can set a string variable to the empty string by assigning "" to it as the following example:

s = "";		/* Sets s to an empty string */

Unlike the C language, a pair of adjacent string literals is not concatenated automatically. The concatenation operator (+) must be explicitly applied as in the following example:

String s[12];

	// s = "abc" "def";	
   /* ERROR: Commented out as this will result in a syntax error */
	s = "abc" + "def";	/* Correct way to concatenate strings */

Vue supports several functions that accept a string data type as a parameter or return a value that has a string data type.