TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program to Separate the Individual Characters from a String

Program to Separate the Individual Characters from a String on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

<< Back to PROGRAM

Program to separate the individual characters from a string

Explanation

In this program, we need to separate each character from the string.

CHARACTERS
C	H	A	R	A	C	T	E	R	S

In computer science, collection of characters including spaces is called as string. To separate an individual character from the string, individual character are accessed through its index.

Algorithm

  1. Define a string.
  2. Define a for-loop in which loop variable will start from 0 and end at length of the string.
  3. To separate each character, we will print the character present at every index.
  4. To visualize this, we have separated each character by a space.

Solution

Python

string = "characters";
 
#Displays individual characters from given string
print("Individual characters from given string:");
 
#Iterate through the string and display individual character
for i in range(0, len(string)):
    print(string[i], end="  ");

Output:

Individual characters from given string: 
c  h  a  r  a  c  t  e  r  s  

C

#include <stdio.h>
#include <string.h>
 
int main()
{
    char string[] = "characters";
        
    //Displays individual characters from given string
    printf("Individual characters from given string:\n");
    
    //Iterate through the string and display individual character
    for(int i = 0; i < strlen(string); i++){
        printf("%c ", string[i]);
    }
        
    return 0;
}

Output:

Individual characters from given string:
c  h  a  r  a  c  t  e  r  s  

JAVA

public class IndividualCharacters
{
    public static void main(String[] args) {
        String string = "characters";
        
        //Displays individual characters from given string
        System.out.println("Individual characters from given string:");
        
        //Iterate through the string and display individual character
        for(int i = 0; i < string.length(); i++){
            System.out.print(string.charAt(i) + "  ");
        }
    }
}

Output:

Individual characters from given string:
c  h  a  r  a  c  t  e  r  s  

C#

using System;
                    
public class IndividualCharacters
{
    public static void Main()
    {
        String string1 = "characters";
        
        //Displays individual characters from given string
        Console.WriteLine("Individual characters from given string:");
        
        //Iterate through the string and display individual character
        for(int i = 0; i < string1.Length; i++){
            Console.Write(string1[i] + "  ");
        }
    }
}

Output:

Individual characters from given string:
c  h  a  r  a  c  t  e  r  s  

PHP

<!DOCTYPE html>
<html>
<body>
<?php
$string = "characters";
 
//Displays individual characters from given string
print("Individual characters from given string: <br>");
 
//Iterate through the string and display individual character
for($i = 0; $i < strlen($string); $i++){
    print($string[$i] . "  ");
}
?>
</body>
</html> 

Output:

Individual characters from given string:
c  h  a  r  a  c  t  e  r  s  

Next Topic#




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf