How do I remove the file Extension from a string? -
Sasino97 - 21.10.2011
Hi community
I have a string containing the full path and name of a file, and I want to remove everything behind the last '.', how can I do that?
Thanks for your time
Re: How do I remove the file Extension from a string? - Max_Coldheart - 21.10.2011
Do you mean something like
strdel?
Re: How do I remove the file Extension from a string? -
CyNiC - 21.10.2011
Only using PAWN I don't believe that be possible.
Re: How do I remove the file Extension from a string? -
Sasino97 - 21.10.2011
If not with pawn, do you know a way to make that in C++, so I can plug that function in?
Re: How do I remove the file Extension from a string? - Max_Coldheart - 21.10.2011
Quote:
Originally Posted by [GF]Sasino97
If not with pawn, do you know a way to make that in C++, so I can plug that function in?
|
why can't you use the strdel I gave you?
Re: How do I remove the file Extension from a string? -
CyNiC - 21.10.2011
Quote:
Originally Posted by [GF]Sasino97
If not with pawn, do you know a way to make that in C++, so I can plug that function in?
|
The ****** is your friend:
http://stackoverflow.com/questions/6...-up-for-review
Replace sprintf to sprintf_s for get security, and for linux sprintf don't work, another function is needed, or just remove it, delete the last char and rename the file.
pawn Код:
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#define format snprintf
#endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32
#define format sprintf_s
#endif
Re: How do I remove the file Extension from a string? -
Vince - 21.10.2011
If you have only 1 dot in the filename, then it's easy enough;
pawn Код:
new filename[32] = example.txt,
strdel(filename, strfind(filename, ".", true), strlen(filename))
Re: How do I remove the file Extension from a string? - 0x5A656578 - 21.10.2011
pawn Код:
main() {
// test
new path[] = "path/to/file/with.periods.ext";
remove_extension(path);
printf("path = %s", path);
}
stock delete_extension(path[]) {
new i = -1, j;
// Loop until find the last '.'
while ((j = strfind(path, ".", _, i + 1)) != -1) {
i = j;
}
// Delete .extension
strdel(path, i, i + strlen(path[i]));
}
Re: How do I remove the file Extension from a string? -
CyNiC - 21.10.2011
I was using my know to help him, I'm sorry for give wrong informations, you pointed that I'm
Less by
You, thanks for this, I'm not flaming, is a positive thing.
Re: How do I remove the file Extension from a string? -
Sasino97 - 21.10.2011
Thanks dudes
![Smiley](images/smilies/smile.png)
! You all helped me
![Smiley](images/smilies/smile.png)
Reputation points ++ to you