String is a very popular data type which can be used in different programming languages like JavaScript, Java, Python, C#, PHP, C, C++, PowerShell. String is mainly used to store characters like a text. Alternative data types are an integer, floating point, etc where they are mainly used for mathematical calculations. For example “I am visiting poftut.com” is a string which completely consists of the alphabet. “I visit poftut.com 2 times” is also a string where 2 is used as a text. Event “123” can be used as a string where we do not use it for mathematical operations.
String Examples
In the previous part, we have provided some string examples but we want to provide more detailed examples here too. We can use the following values as strings.
poftut.com www.poftut.com 123poftut I am a string for poftut.com 123 123.456 ???
String or Character Array
Strings consist of multiple characters. Programming languages provide the character type variables where single character value can be set like c
or z
. Strings are named as character array where multiple characters can be defined which is the same as string. For example p
,o
,f
,t
,u
,t
,.
,c
,o
,m
character array is the same as poftut.com
.
Define and Use String For JavaScript
JavaScript is a dynamic and interpreted language where we can create string type variables. We just need to provide a string with double or single quotes like below. Following variables name, address, Age are defined as string variables.
let name='ismail baydan'; address="Ankara"; Age="9";
Define and Use String For Java
Java is interpreted and but strictly defined programming language. We can create string type variables with the String
type like below.
String name="ismail baydan"; String address="Ankara"; String Age="9";
Define and Use String For Python
Python is an interepted language where the variable types are set according to the provided value. We can use a single or double quote in order to define and set string variables.
name='ismail baydan' address="Ankara" Age="9"
Define and Use String For C#
C# is a new programming language according to the other languages and mainly uses Java programming language syntax. string
can be used to define a string variable like below.
string name='ismail baydan'; string address="Ankara"; string Age="9";
Define and Use String For PHP
PHP is a dynamic language where the variable type is decided according to the initialization value. We can use single or double quotes in order to set a variable as a string.
$name='ismail baydan'; $address="Ankara"; $Age="9";
Define and Use String For C/C++
C and C++ programming languages provide very same syntax for string definition. We will define character arrays like string. We also have to specify the string size like below which is 6 in this case. Strings in C and C++ will end with a NULL or \0
in order to specify the end of the string.
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
STRING TYPE VARIABLE DEFINITION INFOGRAPHING
