21-Jul-2021
.
Admin
Hi Guys,
Now let's see example of how to remove "-"(dash) from string in python. I would like to share with you python remove hyphen from string. We will show how to replace dash to space using python.
If you want to remove hyphen from string in python then you can use this example. In this example how do i remove hyphen from string using python.
Here i will give you two example for how to remove hyphen from string in python. So let's see below example:
Example 1
#Python Remove hyphen from string
myStr = "123-456-789"
# printing original string
print("The original string is : " + myStr)
# Remove hyphen from string
result = myStr.replace('-','')
# printing result
print ("String hyphen remove after : " + str(result))
Output:
The original string is : 123-456-789
String hyphen remove after : 123456789
Example 2
#Python Remove hyphen from string
myStr = "hello-nicesnippets"
# printing original string
print("The original string is : " + myStr)
# Remove hyphen from string
result = myStr.replace('-',' ')
# printing result
print ("String hyphen remove after : " + str(result))
Output:
The original string is : hello-nicesnippets
String hyphen remove after : hello nicesnippets
It will help you....
#Python