How to trim .key off the end of string

  • Thread starter Thread starter laurasaur
  • Start date Start date
L

laurasaur

Hiya guys, have read in a file name but its in a weird format, like
this
filename.date.key

i need to trim off .key any ideas? TrimEnd is not filling me with joy.

Cheers
Laura
 
laurasaur said:
Hiya guys, have read in a file name but its in a weird format, like
this
filename.date.key

i need to trim off .key any ideas? TrimEnd is not filling me with joy.

if (filename.EndsWith(".key"))
{
filename = filename.Substring (0, filename.Length-4);
}
 
if (filename.EndsWith(".key"))
{
filename = filename.Substring (0, filename.Length-4);

}

I did something similar in the end,

//string name = the file name string

int position = name.LastIndexOf('.');
string Sendbak = name.Remove(position);

As I already know that the file will always have a .key extension.
Thanks for all your help everyone
 
laurasaur said:
I did something similar in the end,

//string name = the file name string

int position = name.LastIndexOf('.');
string Sendbak = name.Remove(position);

As I already know that the file will always have a .key extension.
Thanks for all your help everyone

If you already know it will already have a .key extension, you can just
use:

string Sendbak = name.Remove(name.Length-4);

Somehow I'd managed to miss the addition of the "Remove" method in 2.0
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top