substringBefore macro does not work in live template

Hi all, I'm trying to use substringBefore macro in my live template but it keeps printing empty string. Basically I have a file `something.spec.ts` and I want to get the `something` string. I tried `substringBefore(fileName(), ".")` or just `substringBefore("something.spec.ts", ".")` but it keeps printing an empty string. If I try just `fileName()` it correctly prints the filename, in other words all other macros work as expected except for this one. Can you help me please? Can you at least provide some valid example of this macro? 

 

My WebStorm version: 2018.1.4, May 21, 2018

 

0
4 comments

Hi there,

Please post the screenshot of your Live Template.

It works fine here in PhpStorm 2018.1.5 (PHP context .. but that does not matter)

Quite possibly you have not saved it properly (sometimes it's tricky to save the Expression column value).

2
Avatar
Lukáš Havrlant

Hmm, I tried on different machine and it works. The only difference is OS: it works on my Windows machine, it doesn't work on my Linux machine. I'll post the screen tomorrow, I'm not at work right now. 

 

0
Avatar
Lukáš Havrlant

Well, it works now even on my Linux machine ... so I suppose it was the saving thing. Thank you! 

0

Came across this old post because I seemed to be having the same issue. For anyone who finds this, make sure you are using double quotes and not single quotes in the expression.

Example:
substringBefore(fileName(), ".") <- works
substringBefore(fileName(), '.') <- does not work, writes an empty string

1

Please sign in to leave a comment.