Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extrapolate a specific element in a filename
#1
Let's say that I have a macro that creates variables from filenames in a folder, such that:

Folder C:\Folder1 has the files
fileName{topic1}.txt
otherFileName{topic2}.txt

And that the generated variables are:

var1 = fileName{topic1}.txt
var2 = otherFileName{topic2}.txt

And that I want to create a new variable from the contents inside the " { } " characters of that filename, such that

newVar1 = topic1
newVar2 = topic2

Could someone provide an example of how to extrapolate the contents inside the "{ }" of the variable that has the filename and create a new variable from that content, such as 'var1' & 'var2' above.

AND AS ALWAYS, THANK YOU!!!!!!!!!!!!!

Kent
#2
Easiest - with regular expression. if don't want to learn regular expressions, use other string functions, eg findc (to find '{' and '}') and str.get.

Macro Macro2660
Code:
Copy      Help
str var1 = "fileName{topic1}.txt"
str newVar1
if(findrx(var1 "\{(.+?)\}.txt$" 0 1 newVar1 1)<0) end "{...} not found in the string"
out newVar1
#3
Thank you once again!


Forum Jump:


Users browsing this thread: 1 Guest(s)