Israel

Israel

  • 690
  • 1.3k
  • 219.6k

How to remove last word separated by a dot (...)

Jan 24 2020 11:31 PM
How to remove last word separated by a dot without displaying messageBox. Just displaying inside textbox
 
Hi,
 
My codes need some corrections.
 
I have into my textbox numbers separated by dot (for example: 1.5.6.7), then I need to remove the last number with the dot before (for example colored in red: 1.5.6.7) . Curiosly its works ONLY separating by space not by dot (for exampe: 1 5 6 7). This number should be fixed only inside of texbox.
  1. private string strcut(string str)  
  2. {  
  3. string[] a = str.Trim().Split(' ');  
  4. string str1 = string.Empty;  
  5. for (int i = 0; i < a.Count() - 1; i++)  
  6. {  
  7. str1 = str1 + a[i];  
  8. if (a.Count() - 2 != i)  
  9. { str1 += " "; }  
  10. }  
  11. return str1;  
  12. }  
  13. private void btnTest_Click(object sender, EventArgs e)  
  14. {  
  15. string str = textBox1.Text;  
  16. MessageBox.Show(strcut(str));  
  17. }  

Answers (6)