Print given sentence into its equivalent ASCII form

07 Jul, 2022
Given a string containing words forming a sentence(belonging to english language). The task is to output the equivalent ASCII sentence of the input sentence. ASCII form of a sentence is the conversion of each of the character of the input string and aligning them in position of characters present in the stringExamples:  
Input : hello, world!
Output : ASCII Sentence:
         104101108108111443211911111410810033

Input : GeeksforGeeks
Output : ASCII Sentence:
         7110110110711510211111471101101107115
 
Explanation:To complete the task, we need to convert each character into it’s equivalent ASCII value. We perform the following steps to achieve the equivalent ASCII form of the given sentence-  
Iterate over the length of the complete sentence/string
Take each character of the sentence at a time, subtract NULL character to it and explicitly typecast the result
Print the result
Following the above steps, we can achieve the equivalent ASCII form of a given sentence/string. 
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation for converting// a string into it's ASCII equivalent sentence#include <bits/stdc++.h>using namespace std;  // Function to compute the ASCII value of each// character one by onevoid ASCIISentence(std::string str){    int l = str.length();    int convert;    for (int i = 0; i < l; i++) {        convert = str[i] - NULL;        cout << convert;    }}  // Driver functionint main(){    string str = "GeeksforGeeks";    cout << "ASCII Sentence:" << std::endl;    ASCIISentence(str);    return 0;}
// Java implementation for converting// a string into it's ASCII equivalent sentenceimport java.util.*;import java.lang.*;  class GeeksforGeeks {      // Function to compute the ASCII value of each    // character one by one    static void ASCIISentence(String str)    {        int l = str.length();        int convert;        for (int i = 0; i < l; i++) {            convert = str.charAt(i);            System.out.print(convert);        }    }      // Driver function    public static void main(String args[])    {        String str = "GeeksforGeeks";        System.out.println("ASCII Sentence:");        ASCIISentence(str);    }}
# Python3 implementation for# converting a string into it's# ASCII equivalent sentence  # Function to compute the ASCII# value of each character one by onedef ASCIISentence( str ):          for i in str:        print(ord(i), end = '')    print('\n', end = '')      # Driver codestr = "GeeksforGeeks"print("ASCII Sentence:")ASCIISentence(str)  # This code is contributed by "Sharad_Bhardwaj".
// C# implementation for converting// a string into it's ASCII equivalent sentenceusing System;  class GeeksforGeeks {      // Function to compute the ASCII value    //  of each character one by one    static void ASCIISentence(string str)    {        int l = str.Length;        int convert;        for (int i = 0; i < l; i++)        {            convert = str[i];            Console.Write(convert);        }    }      // Driver function    public static void Main()    {        string str = "GeeksforGeeks";        Console.WriteLine("ASCII Sentence:");        ASCIISentence(str);    }}  // This code is contributed by vt_m.
<?php // PHP implementation for converting a // string into it's ASCII equivalent sentence  // Function to compute the ASCII// value of each character one by onefunction ASCIISentence($str){    for ($i = 0; $i< strlen($str); $i++)        echo ord($str[$i]);}      // Driver code$str = "GeeksforGeeks";echo "ASCII Sentence:"."\n";ASCIISentence($str);  // This code is contributed // by ChitraNayal?>
<script>// Javascript implementation for converting// a string into it's ASCII equivalent sentence              // Function to compute the ASCII value of each    // character one by one    function ASCIISentence(str)    {        let l = str.length;        let convert;        for (let i = 0; i < l; i++) {            convert = str[i].charCodeAt(0);            document.write(convert);        }    }          // Driver function    let str = "GeeksforGeeks";    document.write("ASCII Sentence:<br>");    ASCIISentence(str);          // This code is contributed by rag2127</script>
Output:  
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
English
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
ASCII Sentence:
7110110110711510211111471101101107115
Time Complexity: O(N), as we are using a loop to traverse N times. Where N is the length of the string.
Auxiliary Space: O(N), as we are using extra space for convert string.Application: 
Sentence in english language could be encoded/decoded into this form e.g. convert a sentence into it’s equivalent ASCII form and add 5 to each digit and send it from encoder’s side. Later, decoder can subtract 5 from each digit and decode it into it’s original form. This way only the sender and the receiver would be able to decode the sentence.
ASCII form is also used to transfer data from one computer to another.
 
ukasp
rag2127
simmytarika5
rohitsingh57
ASCII
Strings
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Top 50 String Coding Problems for Interviews
What is Data Structure: Types, Classifications and Applications
Print all the duplicates in the input string
Print all subsequences of a string
A Program to check if strings are rotations of each other or not
String class in Java | Set 1
Find if a string is interleaved of two other strings | DP-33
Remove first and last character of a string in Java
Check if an URL is valid or not using Regular Expression
Find the smallest window in a string containing all characters of another string