Assume I have a string "2.36" and I want it trimmed to "236"
I used Trim function in example
String amount = "2.36";
String trimmedAmount = amount.Trim('.');
The value of trimmedAmount is still 2.36
When amount.Trim('6');
it works perfectly but with '.'
What I am doing wrong?
Thanks a lot Cheers
Use the String. replace() method to remove all dots from a string, e.g. const dotsRemoved = str. replace(/\./g, ''); . The replace() method will remove all dots from the string by replacing them with empty strings.
To remove dot and number at the end of the string, we can use gsub function. It will search for the pattern of dot and number at the end of the string in the vector then removal of the pattern can be done by using double quotes without space.
Answer : Use [^[:alnum:]] to remove ~! @#$%^&*(){}_+:"<>?,./;'[]-= and use [^a-zA-Z0-9] to remove also â í ü Â á ą ę ś ć in regex or regexpr functions.
Python String | strip() The strip() method in-built function of Python is used to remove all the leading and trailing spaces from a string. Parameter: chars(optional): Character or a set of characters, that needs to be removed from the string.
Trimming is removing characters from the start or end of a string.
You are simply trying to remove the .
, which can be done by replacing that character with nothing:
string cleanAmount = amount.Replace(".", string.Empty);
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