Reading String from last character downwards

sabzamsabzam Member Posts: 1,149
Hi to everyone,

How can I read a string from the last character backwards and stopping for example when a '\' is found? What I am doing is trying to get the file name from a whole path

Can anyone help pls?

Regards

Answers

  • niscoxniscox Member Posts: 15
    Not exactly what you asked for, but i used this for separating filename and directory from a given path.
    WHILE STRPOS(filename,'\') <> 0 DO
      BEGIN
        path +=  COPYSTR(filename,1,STRPOS(filename,'\'));
        filename := DELSTR(filename,1,STRPOS(filename,'\'));
      END;
    
  • kapamaroukapamarou Member Posts: 1,152
    Or:
    FOR i := STRLEN("MyString") DOWNTO 1 DO BEGIN
      MESSAGE('%1',COPYSTR("MyString",i,1));
    END;
    
    :?:
  • sabzamsabzam Member Posts: 1,149
    Thanks for your answer,

    The function as it is gets the path a removes the file name
    But what if I needed the file name instead of the path?

    Regards
  • jversusjjversusj Member Posts: 489
    check this thread: viewtopic.php?f=23&t=29284&hilit=SplitDirFile

    the SplitDirFile function does what you need, i believe.
    kind of fell into this...
  • sabzamsabzam Member Posts: 1,149
    Thanks alot for the thread....problem solved
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,499
    [The use of [SOLVED] in the Topic Title is no longer supported. Please edit the first message in the thread and use the field Attribute (below the Subject-field) to put a green checkmark next to the Topic Title]
  • niscoxniscox Member Posts: 15
    In my example the variable path holds the path and the variable filename the filename.
    Really..
    Try it
Sign In or Register to comment.