I have a string containg alphabetic characters, for example:
I want to remove all the alphabetic characters (units) from the above mentioned strings so that I can call the double.Parse()
method.
Python Remove Character from String using replace() We can use string replace() function to replace a character with a new character. If we provide an empty string as the second argument, then the character will get removed from the string.
Use the replace Function to Remove a Character From String in Java. The replace function can be used to remove a particular character from a string in Java. The replace function takes two parameters, the first parameter is the character to be removed, and the second parameter is the empty string.
Python Remove Character from a String – How to Delete Characters from Strings. In Python you can use the replace() and translate() methods to specify which characters you want to remove from a string and return a new modified string result.
This should work:
// add directive at the top using System.Text.RegularExpressions; string numberOnly = Regex.Replace(s, "[^0-9.]", "")
You should be able to solve this using Regex. Add the following reference to your project:
using System.Text.RegularExpressions;
after that you can use the following:
string value = Regex.Replace(<yourString>, "[A-Za-z ]", ""); double parsedValue = double.Parse(value);
Assuming you have only alphabetic characters and space as units.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With