INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: need some help with an expression  (Read 2207 times)

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
need some help with an expression
« on: February 04, 2013, 08:37:33 am »

i want to make an expression to copy keywords to the notes field. but all the keywords should be seperated by a return. everyone of them has its own line..

thanks
 :)
gab
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: need some help with an expression
« Reply #1 on: February 04, 2013, 01:30:45 pm »

I can't think of any way to introduce a newline into an expression.  Regex() stops at newlines, so we can't capture an embedded one.

Edit for strikeout above: Regex() does not stop at newline; rather, the flag Dot Matches Newline is unset, so it is not possible to use dot to capture a newline; this also implies that you cannot span lines using .* or .+.  Regex() does support \n escapes, so you can capture one of those directly:

   Regex([field with newline], #/(\n)#/, ...

MC should support \n and \r in output for large text fields, so that fields such as [Notes] can be built from other fields.

I think it should also support the flag for Regex() that allows Dot Matches Newlines; otherwise it is generally not possible to pull data across multiple lines in [Notes].
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
HowTo: Substitute a character with a newline (for Notes, etc.)
« Reply #2 on: February 04, 2013, 03:06:35 pm »

Solved!

I hadn't thought to test another way.

In a single Notes field, add a single newline (just hit return).  Take note of the record you are adding this to.  For example, perhaps it is a file with Name=FooBar

Add an expression column, or equivalent syntax in Set rules for file display, adding:

   if(isequal([Name],FooBar),save([Notes],newline),Ignored)

Now, for the file(s) you want to change, edit Notes and enter:

   =replace([keywords],;/ , [newline])

This grabs the single newline from the global variable newline and replaces the keywords semicolon/space delimiter with the newline.
Logged
The opinions I express represent my own folly.

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: need some help with an expression
« Reply #3 on: February 04, 2013, 04:06:35 pm »

brilliant! creative and crazy. i love it  :P

it works. i also tried regex stuff, but im not good in it, and im happy to hear that that was not the only problem. but never thought i could use a global variable for it, and in that way.
i think i can streamline it a bit for regular use.

thank you very much
 :)
gab
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: need some help with an expression
« Reply #4 on: February 04, 2013, 04:44:30 pm »

I've updated my comments above.  You can use Regex() to capture a newline.  It just has to be done specifically, rather than by using the match-any character dot.  The expression:

   Regex([field with newline], #/(\n)#/, 1)

will output a single newline, and capture [R1] can be used as well.
Logged
The opinions I express represent my own folly.

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: need some help with an expression
« Reply #5 on: February 04, 2013, 05:27:15 pm »

thank you again.. ofcourse i could not get it to work. its to late to think clear enough, i really need to get into this regex stuf. but tomorrow i will. today i found this \n on some site and tried. now i need to understand. i will get it.

thanks
 :)
gab

ps: your first solution i did understand, and works very nice. made it the way i wanted, and my viz studio thing starts to give the info i want and even to look nice..... it was a good mc-day.

Logged

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: need some help with an expression
« Reply #6 on: February 04, 2013, 06:22:55 pm »

Does this mean that there is a way I could use new line in an expression field to be used in thumbnail text, i.e. to output new line and "something" only if there was "something" to output?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: need some help with an expression
« Reply #7 on: February 04, 2013, 06:28:17 pm »

Does this mean that there is a way I could use new line in an expression field to be used in thumbnail text, i.e. to output new line and "something" only if there was "something" to output?

In Thumbnail text, when the newline comes from a field's value, it appears MC replaces the newline and everything after it with ... .
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: need some help with an expression
« Reply #8 on: February 05, 2013, 03:29:56 am »

Thanks for the replay.

In Thumbnail text, when the newline comes from a field's value, it appears MC replaces the newline and everything after it with ... .

Too bad. It was close though. I had not even figured out how to put new line in an expression field.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: need some help with an expression
« Reply #9 on: February 05, 2013, 10:40:52 am »

Neat solution, very neat.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: need some help with an expression
« Reply #10 on: February 05, 2013, 01:37:22 pm »

thank you again.. ofcourse i could not get it to work. its to late to think clear enough, i really need to get into this regex stuf. but tomorrow i will. today i found this \n on some site and tried. now i need to understand. i will get it.

The regex() I posted wasn't a complete solution, so it wouldn't work without the additional code.  It was a proof that a newline can be captured and later used.  To use it, you'd want to use this in some column:

   ifelse(regex([Notes],/#(\n)#/),save([R1],newline))

It won't produce any output, but does set the newline variable so long as some Notes field has a newline in it.  You could also perform it in the Set rules for files display with a custom rule:

    [=ifelse(regex([Notes],/#(\n)#/),save([R1],newline))1]=1

and this will make the newline value set for the view (no empty expression column necessary).  If you set this for the top level Audio view, all your child views will then have access to the pseudo-field [newline], and you can use it freely henceforth.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up