MATRIXx

cancel
Showing results for 
Search instead for 
Did you mean: 

TPL string manipulation question

Question 1:
 
"\" is being used as scape charecter for double quote (")  in a constant string. How could one search for \ in a string?
 
The  following code produces the line in the red color:
 
 
@S1 = "s:\aaa\bbb"@
@S2 = "\" @
@IFF STRSTR(S1,S2)@
@S2=STRSTR(S1,S2)@
S2=@S2@
@ELSE@
Variable     --@S2@--    not found.
@ENDIFF@
 
 

Variable    --"--    not found.

 

Question 2:

Is there a TPL function to extract subpart of a string (e.g., the first 5 characters)?

Question 3:

Is there a TPL function to extract file name and path (e.g., for "S:\aaa\foo.c" extracts S:\aaa and bbb.c )?

 

 

Thanks

 

Farshid

0 Kudos
Message 1 of 6
(10,460 Views)
Hello Farshid,
      Have you had a chance to look at the MatrixX Template Programming Language Users Guide?  Please take a look at the example on pg 2-31.

Cheers,

NathanT
0 Kudos
Message 2 of 6
(10,446 Views)
 
I had already looked at the document and section that you mentioned - it  does not provide any answer to my questions.
 
Thanks
 
 
Farshid
0 Kudos
Message 3 of 6
(10,434 Views)
Hello Farshid,
       Regarding Question 1:

It is not currently possible to create a string that only has a backslash character.  I will let R&D know about this and post the CAR ID.

       Regarding Questions 2&3:
       Unfortunately, there are no additional string manipulation TPL functions and definitely no filename manipulation routines. I'd suggest that if you must use pathnames, that you keep the path and the filename in separate variables and combine them only when you need to manipulate the file. That way, the TPL code and independently access the filename and path. Also, you might want to consider using user parameters, which is a way to get user data specified in a model diagram into TPL for processing. You could have a user parameter for the path and another for the filename.

I will file a product suggestion for more string manipulations and pathname functions.

Cheers,

NathanT
      

0 Kudos
Message 4 of 6
(10,429 Views)
Thanks Nathan.
 
I am attaching a TPL segment (poor man solution) that will extract the path and file name from a string representing the full file name (including the path).
The script uses the very limited set of functions that are available.
 
Note that since it is not currently possible to create a string that only has a backslash (\) character,  it only works on unix style file path (with /).
 
Farshid 
0 Kudos
Message 5 of 6
(10,419 Views)
Farshid,

This was reported to R&D (# 46CQ5ZQ) for further investigation.  Thanks for the feedback!

NathanT
0 Kudos
Message 6 of 6
(10,387 Views)