Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove dot character from a String C#

Tags:

c#

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

like image 839
Pinchy Avatar asked Apr 24 '12 13:04

Pinchy


People also ask

How do I remove a dot from a string?

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.

How do I remove the period from a string in R?

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.

How do I remove numbers and special characters from a string in R?

Answer : Use [^[:alnum:]] to remove ~! @#$%^&*(){}_+:"<>?,./;'[]-= and use [^a-zA-Z0-9] to remove also â í ü Â á ą ę ś ć in regex or regexpr functions.

How do you remove the dot from a string in Python?

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.


1 Answers

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);
like image 53
Oded Avatar answered Oct 13 '22 09:10

Oded