How to remove 1 segment from the "macro_path(0)"

ps
Contributor
Contributor

How to remove 1 segment from the "macro_path(0)"

ps
Contributor
Contributor

Hi

How do i remove the last part of a string if i dont no its lenght?

STRING mpt = macro_path(0) 

This prints D:\lokalt\1 folder\more projektes

If I want to remove all after the last \ so I get  D:\lokalt\1 folder

 

0 Likes
Reply
Accepted solutions (1)
485 Views
5 Replies
Replies (5)

rafael.sansao
Advisor
Advisor
STRING mpt = macro_path(0)
STRING LIST tk = tokens($mpt, '/')
$mpt = REPLACE($mpt, "/" + $tk[SIZE($tk)-1], "")

MESSAGE INFO $mpt

Rafael Sansão

EESignature

LasseFred
Collaborator
Collaborator

Take @rafael.sansao macro and edit / to \ and it works..

 

STRING mpt = macro_path(0)
STRING LIST tk = tokens($mpt, '\')
$mpt = REPLACE($mpt, "\" + $tk[SIZE($tk)-1], "")

MESSAGE INFO $mpt

 

______________________
Lasse F.
0 Likes

rafael.sansao
Advisor
Advisor

This depends on the language of the computer... / OR \

Rafael Sansão

EESignature

richard.pedley
Autodesk
Autodesk
Accepted solution

Hi PS,

 

The function dirname does this:

STRING $Test1 = macro_path(0)
$Test1 = dirname($Test1)

That should sort it for you.

 

Hope that helps

 

Richard



Richard Pedley
Research Engineer

ps
Contributor
Contributor

Thanks this works perfect Smiley Happy

 

0 Likes