Extracting a text string between specific characters using Named Expressions


Product(s):AECOsim Building Designer
Version(s):08.11.09.866
Environment:N\A
Area:Platform Tools
Subarea:N\A

Problem Description

I've been able to successfully set up a Named Expression to parse my DGN file names, however I can't find a way to extract a specific variable length text string that consistently falls between specific characters.  For example, I have a DGN file named "MV_A01_Proyecto__Project.dgn where the first characters are the project code, the next set is the sheet number, and the next two represent a bi-lingual version of "Project". 

I am able to get the project code extracted since it always uses three characters:
System.String.Substring(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),3,3)

The second set of characters are extracted beginning with the "_" until the end of the file name:
IIf (System.String.Indexof (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__") >= 0,System.String.Substring (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), System.String.Indexof (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__") +2, -1),System.Path.GetFileNameWithoutExtension (ActiveFile.FileName))

However, that middle Spanish translation may change character lengths so I would like to parse the text string that falls between "_" and "_".   Is this possible?

Steps to Resolve

Yes, if you can change the file naming convention to use a double "__" on both sides of that text string, the following expressions may work when plugged into your IF statement:

FileName_Last

System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.LastIndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, -1)

FileName_Next Last

System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.IndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, Session.EvalNEAsInt ("FileName_NextLastMinusLast",0)  )

FileName_NextLastMinusLast

System.String.Length(System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.IndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, -1))
-
System.String.Length(System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.LastIndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__"), -1))


The "FileName_NextLastMinusLast" expression essentially returns a number difference between Proyecto__Project "and" Project and is used in the expression "FileName_Next Last".   Expressions could also be adjusted to potentially trim mv_A01_Situación-Situation.dgn.

See Also

http://communities.bentley.com/products/microstation/microstation_printing/f/19568/p/113250/349437#349437

 Original Author:Steve Cocchi