Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, i have some values in my datagridview with dots like large. small.
i want to remove. on button click i am vary confused that how can do it please help me
see what am trying but am getting an error please suggest me best code for it
Thanks

What I have tried:

if(dataGridView1.Rows[i].Cells[3].Value.ToString().Contains("."))
                        {
                            dataGridView1.Rows[i].Cells[3].Value.ToString().Trim().Split(-1);
                        }
Posted
Updated 24-Jul-17 16:16pm
Comments
Patrice T 25-Jul-17 3:03am    
After 86 questions, do you have plan to learn really the language ?

Use below code..

if(inputText.Trim().EndsWith("."))
{
string outputText = inputText.Remove(inputText.Length - 1, 1);
}


Here
inputText
is your gridview cell text.

Other way around is to create an extension method and call it to remove last char after checking if the last char is dot.

public static class MyExtensions
{
  public static string TrimLastCharacter(this String str)
  {
     if(String.IsNullOrEmpty(str)){
        return str;
     } else {
        return str.TrimEnd(str[str.Length - 1]);
     }
  }
}
 
Share this answer
 
v2
Use String.Substring Method[^] to get a sub-section of a string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900