C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to separate the individual characters from a stringExplanationIn 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
SolutionPythonstring = "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 JAVApublic 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#
|