String is one of the value types defined in a solidity programming language.

String variables can be declared using the string keyword.

string types can be declared as a variable with global or local.

How to declare a variable of a string?

Variables declared of a string with the below syntax.

string [scope] name;

scope is an optional such as public, private, and valid solidity scopes. string is a keyword and data type defined in the language. name is an identifier declared and valid names are alphanumeric which starting must be a letter. Reserved words not used with name value.

Another way using `string literal syntax allows you to declare and assign the values with a single statement.

string public name = "john";

String literals are enclosed in double quotes(") or single quotes(')

If it is declared in a global contract, called a global scope variable

pragma solidity ^0.5.0;

// Create contract for String type testing
contract StringTest {
    string name;
    string role="admin";

}

There is another way to declare string types with byte32. Byte32 works with string declaration as well as string literal syntax.

pragma solidity ^0.5.0;

// Create contract for String type testing
contract StringTest {
    byte32 name;
    byte32 role="admin";

}

Both string and byte32 do store the string data.

String takes more gas compared to byte32. It is always preferable to use byte32 in place of string.

Explicit conversion is not required to convert byte32 to/from a string.