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?
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>- 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>)