Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

How to remove the last character, if it is more than 9 character?
Can any one please help me on that.

Example
Question : 30112118617

Answer will be : 301121186
Posted
Comments
Thanks7872 30-Oct-13 5:53am    
Help you with what? Have you tried some thing? If yes then what is the issue? Where is the code?
BillWoodruff 30-Oct-13 7:39am    
This is almost the same question that this person posted yesterday:

http://www.codeproject.com/Questions/675554/how-to-get-remove-last-two-digits-if-it-11-or-12

To which he received five answers.

Try:
C#
string s = "30112118617";
if (s.Length > 9)
    s = s.Remove(9);
// now, s is 301121186
 
Share this answer
 
Me too
C#
string s = "30112118617";
int maxLength = 9;
if(s.Length > maxLength)
{
    s = s.Substring(0, maxLength);
}
 
Share this answer
 
this is the answer ...
C#
string S="30112118617";
      if (S.Length > 9)
      {
          int x = S.Length - 9;
          S = S.Substring(0, S.Length - x);

      }



its working ,, give me a nice accsept solution ...
 
Share this answer
 
v3

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