Monday, May 24, 2010

In c# which function is used to get the last character in a string. how to remove that character from string.?

You can access the last character in a string by treating the string as an array, eg:


lastChar = str[str.Length-1];





To remove it you can use substring to return all but the last character, eg:


str2 = str.Substring(0, str.Length-1);

In c# which function is used to get the last character in a string. how to remove that character from string.?
int k=strlen(str) //where str is ur original string





for ( int i = 0 ; i%26lt;k-1; i++)


{


str1[i]=str[i];


}





// where str1 is some new string name, where your previous string will be saved without the last character





your new string str1 will have all your string data without the last character.
Reply:just get the string length then set the length - 1 to 0.





length = strlen(string)


string[length - 1] = 0


No comments:

Post a Comment