ansi_c
asked on
Get Extension
Hey.. Suppose I have a variable that stores the below value
"abc/def/ghi.txt"
I wish to get the extension which in this case would be txt. How to do that? Note that the length of the extension varies.
Full working example preferred.
"abc/def/ghi.txt"
I wish to get the extension which in this case would be txt. How to do that? Note that the length of the extension varies.
Full working example preferred.
Just to let you know, most often this is done with some function like split() in the language, but we have to be sure to give a working example.
Regards
Regards
Hi ansi_c,
yes it would be easier if we know what language :)
in php you do like this:
$arr = explode(".",$variable);
$extention = arr[count[arr]];
in bash do this:
ext=`echo $variable | sed 's/.*\([^\.]\+\)\.\([^\.]\ +\)$/\2/'`
in c:
bool getextention(char *in, char *out)
{
char *tmp = in;
char *punkt;
for(int i=0; i < sizeof(*in);i++;)
{
if(tmp++ == '.')
punkt = tmp;
}
if(tmp != in)
{
out = tmp;
return TRUE;
}
return FALSE;
}
/Rob
yes it would be easier if we know what language :)
in php you do like this:
$arr = explode(".",$variable);
$extention = arr[count[arr]];
in bash do this:
ext=`echo $variable | sed 's/.*\([^\.]\+\)\.\([^\.]\
in c:
bool getextention(char *in, char *out)
{
char *tmp = in;
char *punkt;
for(int i=0; i < sizeof(*in);i++;)
{
if(tmp++ == '.')
punkt = tmp;
}
if(tmp != in)
{
out = tmp;
return TRUE;
}
return FALSE;
}
/Rob
ASKER
i am doing unix shell scripting.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
de2Zotjes,
smothe solution there.
/Rob
smothe solution there.
/Rob
smothe ?
I am not native english speaking, what am I missing?
I am not native english speaking, what am I missing?
de2Zotjes,
sry I cant spell it should be "smooth" and it means nice, easy in this purpose otherwise it can mean flat, even.
However it was a compliment :)
/Rob
sry I cant spell it should be "smooth" and it means nice, easy in this purpose otherwise it can mean flat, even.
However it was a compliment :)
/Rob
What language are you using?
Regards,
Zyloch