This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

$nopath and $nofile from mirc

Old posts that have not been replied to for several years.
Locked
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

$nopath and $nofile from mirc

Post by cerberus_gr »

Hello,

I would like to write $nopath and $nofile that mirc has in tcl.

examples in mirc

$nofile(/dir1/dir2/dir3/file.type) returns /dir1/dir2/dir3/
$nopath(/dir1/dir2/dir3/file.type) returns file.type

Any help for 2 these procedures?
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

You should be able to do that by using the following string functions:
-----------------------------------------------------------
string length <string>
Returns a decimal string giving the number of characters in string.

string index <string> <charIndex>
Returns the charIndex'th character of the string argument. A charIndex of 0 corresponds to the first character of the string. If charIndex is less than 0 or greater than or equal to the length of the string then an empty string is returned.

string range <string> <first> <last>
Returns a range of consecutive characters from string, starting with the character whose index is first and ending with the character whose index is last. An index of 0 refers to the first character of the string. An index of end (or any abbreviation of it) refers to the last character of the string. If first is less than zero then it is treated as if it were zero, and if last is greater than or equal to the length of the string then it is treated as if it were end. If first is greater than last then an empty string is returned.
---------------------------------------------------------

Here's what you could do for $nofile for example:
- Start by checking the last character of the string (hint: to go to the last character of the string you can use string index <string> <string length - 1>)

- If it's a "/" then stop and return all the string as it is (since it ends with a "/" and it doesn't contain a file name anyway. Assuming it contains more than 1 character of course).

- Else while (current character is not "/" and current_position > 0) move 1 character backwards (hint: use a while loop and decrement a current_position -> use string index <string> <current_position> to check if the character you are positioned at is a "/").

- Here you have just exited the while.
If <current_position> is > 0 then return the string ranging from 0 to <current_position> (hint: use string range <string> 0 <current_position>)
Note: if you want $nopath then, at the end of your code, just return the string ranging from <current_position + 1> to <string length -1>
(string range <string> <current_position + 1> <string length - 1>)

I hope my example (although not very easily explained) gave you an idea on which logic to use.
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

thx a lot for your help. It works great :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Reinventing the wheel...

Post by user »

Check out file dirname and file tail :)
Have you ever read "The Manual"?
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

user where have you been all these days? :P

Thx a lot, even if I have already written 5 lines of code (fortunately only 5 :P)
The "file dirname" and "file tail" works great :)
Locked