How to Declare Strings in various languages?

Below is the representation of strings in various languages:

C++




// C++ program to demonstrate String
// using Standard String representation
  
#include <iostream>
#include <string>
using namespace std;
  
int main()
{
  
    // Declare and initialize the string
    string str1 = "Welcome to w3wiki!";
  
    // Initialization by raw string
    string str2("A Computer Science Portal");
  
    // Print string
    cout << str1 << endl << str2;
  
    return 0;
}


C




// C program to illustrate strings
#include <stdio.h>
  
int main()
{
    // declare and initialize string
    char str[] = "Geeks";
  
    // print string
    printf("%s", str);
  
    return 0;
}


Java




// Java code to illustrate String
import java.io.*;
import java.lang.*;
  
class Test {
    public static void main(String[] args)
    {
        // Declare String without using new operator
        String s = "w3wiki";
  
        // Prints the String.
        System.out.println("String s = " + s);
  
        // Declare String using new operator
        String s1 = new String("w3wiki");
  
        // Prints the String.
        System.out.println("String s1 = " + s1);
    }
}


Python




# Python Program for
# Creation of String
  
# Creating a String
# with single Quotes
String1 = 'Welcome to the Geeks World'
print("String with the use of Single Quotes: ")
print(String1)
  
# Creating a String
# with double Quotes
String1 = "I'm a Geek"
print("\nString with the use of Double Quotes: ")
print(String1)
  
# Creating a String
# with triple Quotes
String1 = '''I'm a Geek and I live in a world of "Geeks"'''
print("\nString with the use of Triple Quotes: ")
print(String1)
  
# Creating String with triple
# Quotes allows multiple lines
String1 = '''Geeks
            For
            Life'''
print("\nCreating a multiline String: ")
print(String1)


C#




// Include namespace system
using System;
  
public class Test
{
    public static void Main(String[] args)
    {
        // Declare String without using new operator
        var s = "w3wiki";
        // Prints the String.
        Console.WriteLine("String s = " + s);
        // Declare String using new operator
        var s1 = new  String("w3wiki");
        // Prints the String.
        Console.WriteLine("String s1 = " + s1);
    }
}


Javascript




<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript Strings
    </title>
</head>
  
<body>
      
    <h1>w3wiki</h1>
      
    <h2>JavaScript Strings</h2>
      
    <p id="GFG"></p>
  
  
      
    <!-- Script to store string in variable -->
    <script>
      
        // String written inside quotes
        var x = "Welcome to w3wiki!";
        document.getElementById("GFG").innerHTML = x;
    </script>
</body>
  
</html>


PHP




<?php
  
// single-quote strings
  
$site = 'Welcome to w3wiki';
  
echo $site;
  
?>


Introduction to Strings – Data Structure and Algorithm Tutorials

Similar Reads

What is String?

Strings are considered a data type in general and are typically represented as arrays of bytes (or words) that store a sequence of characters. Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’...

How String is represented in Memory?

In C, a string can be referred to either using a character pointer or as a character array. When strings are declared as character arrays, they are stored like other types of arrays in C. For example, if str[] is an auto variable then the string is stored in the stack segment, if it’s a global or static variable then stored in the data segment, etc....

How to Declare Strings in various languages?

Below is the representation of strings in various languages:...

General Operations performed on String:

...

1. Concatenation of Strings

...

2. Find in String

...

3. Replace in String

...

4. Finding the Length of String

...

5. Trim a String

...

6. Reverse and Rotation of a String

...

7. Subsequence of a String

Here we are providing you with some must-know concepts of string:...

8. Substring of a String

The process of combining more than one string together is known as Concatenation. String Concatenation is the technique of combining two strings....

9. Binary String

A very basic operation performed on Strings is to find something in the given whole string. Now, this can be to find a given character in a string, or to find a complete string in another string....

10. Palindrome String

Many times, it is very important to make corrections in strings. Replacing a character, word or phrase in a String is another very common operation performed on Strings....

11. Lexicographic Patterns

One of the most general operations on String is to find the length/size of a given string. Length is defined as the number of characters in a string is called the length of that string....

12. Pattern Searching

Spaces or special characters are very common in Strings. So it is important to know how to trim such characters in String....

Top Theoretical Interview Questions

Reverse operation is interchanging the position of characters of a string such that the first becomes the last, the second becomes the second last, and so on....

Top 50 interview coding question

A subsequence is a sequence that can be derived from another sequence by removing zero or more elements, without changing the order of the remaining elements....

Advantages of using String:

A substring is a contiguous part of a string, i.e., a string inside another string....

Disadvantages of String:

A Binary String is a special kind of string made up of only two types of characters, such as 0 and 1.For Example:...

Application of String:

A string is said to be a palindrome if the reverse of the string is the same as the string. For example,...

Frequently asked questions (FAQs) on String

Lexicographical pattern is the pattern based on the ASCII value or can be said in dictionary order. We consider the lexicographic order of characters as their order of ASCII value. Hence the lexicographical order of characters will be...

Conclusion

Pattern searching is searching a given pattern in the string. It is an advanced topic of string. The Pattern Searching algorithms are sometimes also referred to as String Searching Algorithms and are considered as a part of the String algorithms. These algorithms are useful in the case of searching a string within another string....

Contact Us