Javatpoint Logo
Javatpoint Logo

Program to replace the spaces of a string with a specific character

C Program:-

Output:

After replacing the space with  * the new string is :
This*is*an*example*string

Java Program

Output:

Replace space ' ' with '*': This*is*an*example*string

C# Program

Output:

Replace space ' ' with '*':	This*is*an*example*string

Php Program

Output:

This*is*an*example*string

Python Program

After replacing space ' ' with '*' 	This*is*an*example*string

Explanation

In this program, we replace each space of a string with '*'. To achieve this each programming language we have its syntax and library.

In C, there is no specific function in string.h for performing the replacement in String. For performing replacement of space with '*' in the string, we use ctype.h which provides a function to perform conditions on single characters.

In Java, for performing replacement of space with '*' in the string, there is a function named as replace() which is provided to replace a specific character with other characters in String class.

Ex:-


In C#, for performing replacement of space with '*' in the string, there is a function named as Replace() which is provided to replace a specific character with other characters in String class.

Ex:-


In Php, for performing replacement of space with '*' in the string, there is a function named as str_replace() which is provided to replace a specific character with other characters.

Ex:-


In Python, for performing replacement of space with '*' in the string, there is a function named as replace() which is provided to replace a specific character with other characters.

Ex:-


Next TopicPrograms List




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials